feat(work): gate agent canary dispatch
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
"git.cin.su/m/Assistant/modules/work/ports"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCanaryDisabled = errors.New("agent canary is disabled")
|
||||
ErrCanaryNotAllowed = errors.New("agent implementation is not canary-allowed")
|
||||
ErrCanaryLimitReached = errors.New("agent canary dispatch limit reached")
|
||||
)
|
||||
|
||||
type CanaryConfig struct {
|
||||
Enabled bool
|
||||
ImplementationID string
|
||||
MaxDispatches int
|
||||
}
|
||||
|
||||
func ExecuteCanaryDryRun(ctx context.Context, store ports.ExecutionStore, config CanaryConfig, usedDispatches int, intent work.AgentDispatchIntent, workerID string, token work.AgentFencingToken, now time.Time, ttl time.Duration) (work.DryRunDispatch, error) {
|
||||
if !config.Enabled {
|
||||
return work.DryRunDispatch{}, ErrCanaryDisabled
|
||||
}
|
||||
if config.ImplementationID == "" || intent.ImplementationID != config.ImplementationID {
|
||||
return work.DryRunDispatch{}, ErrCanaryNotAllowed
|
||||
}
|
||||
if config.MaxDispatches <= 0 || usedDispatches >= config.MaxDispatches {
|
||||
return work.DryRunDispatch{}, ErrCanaryLimitReached
|
||||
}
|
||||
return ExecuteDryRunDispatch(ctx, store, intent, workerID, token, now, ttl)
|
||||
}
|
||||
Reference in New Issue
Block a user