Skip to main content

Lifecycle Hooks

Register callbacks at every stage of plan execution. The SDK performs no logging — hooks are the only output mechanism.

Hooks

HookSignature
BeforePlanfunc(summary PlanSummary)
AfterPlanfunc(report *Report)
BeforeLevelfunc(level int, tasks []*Task, parallel bool)
AfterLevelfunc(level int, results []TaskResult)
BeforeTaskfunc(task *Task)
AfterTaskfunc(task *Task, result TaskResult)
OnRetryfunc(task *Task, attempt int, err error)
OnSkipfunc(task *Task, reason string)

Usage

hooks := orchestrator.Hooks{
BeforePlan: func(summary orchestrator.PlanSummary) {
fmt.Printf("Plan: %d tasks\n", summary.TotalTasks)
},
AfterTask: func(_ *orchestrator.Task, result orchestrator.TaskResult) {
fmt.Printf(" [%s] %s changed=%v\n",
result.Status, result.Name, result.Changed)
},
}

plan := orchestrator.NewPlan(client, orchestrator.WithHooks(hooks))

Example

See examples/sdk/orchestrator/features/hooks.go for a complete working example demonstrating all 8 hooks.