Documentation
¶
Overview ¶
Package supervisor provides retry, restart, and escalation policies for GRIP execution pipelines.
The Supervisor orchestrates execution using configurable policies. It never executes user code directly — it delegates to an Executor and applies retry/restart/escalation logic based on the result.
Policies ¶
- RetryPolicy: max attempts, backoff duration, jitter
- DeadlinePolicy: timeout per execution
- AdmissionPolicy: max concurrency
- EscalationPolicy: escalate-on-panic, escalate-on-retry-exhausted
Hooks ¶
The hook system provides callbacks at each lifecycle stage:
- OnStart: called before execution begins
- OnSuccess: called after successful execution
- OnFailure: called after failed execution
- OnRetry: called before each retry attempt
- OnGiveUp: called when all retries are exhausted
Each hook is wrapped in recover() to prevent callback panics from crashing the pipeline.
Index ¶
Constants ¶
const ( // Successful Execution FailureSuccess = core.FailureNone // Returned error (non-panic) FailureErr = core.FailureHandlerError // Panic occurred FailurePanic = core.FailurePanic // Context cancelled by caller FailureCancelled = core.FailureContextCancelled // Deadline exceeded (treated as cancellation in core) FailureDeadline = core.FailureContextCancelled // System shutdown FailureShutdown = core.FailureShutdown )
Backward compatibility constants - mapped to core.FailureKind
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffPolicy ¶
type EscalationPolicy ¶
type ExecutorRunner ¶
type ExecutorRunner interface {
Execute(exec core.Execution, fn func(context.Context) error) execution.Result
}
ExecutorRunner is the minimal interface Supervisor depends on. This avoids tight coupling and allows mocking in tests.
type ExponentialBackoff ¶
Exponential backoff
type FailureKind ¶
type FailureKind = core.FailureKind
FailureKind is now an alias to core.FailureKind for backward compatibility. See core/failure.go for the authoritative definition.
type Hooks ¶
type Hooks struct {
// Called exactly once when execution starts
OnStart func(ctx context.Context)
// Called exactly once when execution completes successfully
OnSuccess func(ctx context.Context)
// Called exactly once when execution fails
OnFailure func(ctx context.Context, failure FailureKind)
// Called when supervisor decides to retry execution
OnRetry func(ctx context.Context, attempt int)
// Called when supervisor permanently gives up
OnGiveUp func(ctx context.Context, failure FailureKind)
}
type RestartPolicy ¶
type RestartPolicy int
const ( // Never restart a child RestartNever RestartPolicy = iota // Restart only on failure (error or panic) RestartOnFailure // Restart even after success RestartAlways )
type RetryPolicy ¶
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor orchestrates execution using policies. It NEVER executes user code directly.
func NewSupervisor ¶
func NewSupervisor( executor ExecutorRunner, policy SupervisorPolicy, hooks Hooks, ) *Supervisor
NewSupervisor constructs a Supervisor.
func (*Supervisor) Run ¶
func (s *Supervisor) Run( ctx context.Context, exec core.Execution, fn func(context.Context) error, ) execution.Result
Run executes an execution under supervision.
Contract: - fn is passed THROUGH to executor, never called directly - retries, restarts, escalation handled here
type SupervisorPolicy ¶
type SupervisorPolicy struct {
Retry RetryPolicy
Restart RestartPolicy
Escalation EscalationPolicy
Backoff BackoffPolicy
}
Supervisor Policy
func (SupervisorPolicy) ShouldEscalate ¶
func (p SupervisorPolicy) ShouldEscalate( kind FailureKind, retriesExhausted bool, ) bool
ShouldEscalate decides whether failure should propagate upward.
func (SupervisorPolicy) ShouldRestart ¶
func (p SupervisorPolicy) ShouldRestart(kind FailureKind) bool
ShouldRestart decides whether child should be restarted.
func (SupervisorPolicy) ShouldRetry ¶
func (p SupervisorPolicy) ShouldRetry( kind FailureKind, attempt int, ) bool
ShouldRetry decides whether another retry attempt is allowed.