Complete the core operation execution cutover
This commit is contained in:
@@ -8,9 +8,9 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
// FinishProducerFailure applies the resolved terminal mode without retrying
|
||||
// finishProducerFailure applies the resolved terminal mode without retrying
|
||||
// production or running ordinary validators against a supported fallback.
|
||||
func FinishProducerFailure[T any](ctx context.Context, mode contracts.ExecutionMode, cause error, fallback func(context.Context) (T, error)) (T, contracts.ProducerOutcome, error) {
|
||||
func finishProducerFailure[T any](ctx context.Context, mode contracts.ExecutionMode, cause error, fallback func(context.Context) (T, error)) (T, contracts.ProducerOutcome, error) {
|
||||
var zero T
|
||||
if ctx == nil {
|
||||
return zero, contracts.ProducerOutcome{}, errors.New("producer context must not be nil")
|
||||
@@ -44,30 +44,3 @@ func FinishProducerFailure[T any](ctx context.Context, mode contracts.ExecutionM
|
||||
return zero, contracts.ProducerOutcome{}, fmt.Errorf("unsupported producer mode %q", mode)
|
||||
}
|
||||
}
|
||||
|
||||
// AssessProducer assesses a no-model result once, including deterministic
|
||||
// short-circuits inside otherwise model-backed modules. It never constructs a
|
||||
// native request or gives deterministic work a correction loop.
|
||||
func AssessProducer[T any](ctx context.Context, operation contracts.ProducerOperation[T], value T, fallback func(context.Context) (T, error)) (T, contracts.ProducerOutcome, error) {
|
||||
var zero T
|
||||
if ctx == nil {
|
||||
return zero, contracts.ProducerOutcome{}, errors.New("producer context must not be nil")
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return zero, contracts.ProducerOutcome{}, err
|
||||
}
|
||||
if operation.Assess == nil {
|
||||
return zero, contracts.ProducerOutcome{}, errors.New("producer assessment must be supplied")
|
||||
}
|
||||
assessment, err := operation.Assess(ctx, value)
|
||||
if err != nil {
|
||||
return zero, contracts.ProducerOutcome{}, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return zero, contracts.ProducerOutcome{}, err
|
||||
}
|
||||
if !assessment.Accepted() {
|
||||
return FinishProducerFailure(ctx, operation.Controls.Mode, assessment.Err(), fallback)
|
||||
}
|
||||
return value, contracts.ProducerOutcome{Disposition: contracts.ProducerAccepted, ReuseEligible: operation.ReuseEligible}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user