Documentation
¶
Overview ¶
Package engine provides DAG-based task orchestration primitives.
Index ¶
- Variables
- func StructToMap(v any) map[string]any
- type ErrorStrategy
- type GuardFn
- type Hooks
- type HostResult
- type Plan
- func (p *Plan) Client() *osapiclient.Client
- func (p *Plan) Config() PlanConfig
- func (p *Plan) Explain() string
- func (p *Plan) Levels() ([][]*Task, error)
- func (p *Plan) Run(ctx context.Context) (*Report, error)
- func (p *Plan) TaskFunc(name string, fn TaskFn) *Task
- func (p *Plan) TaskFuncWithResults(name string, fn TaskFnWithResults) *Task
- func (p *Plan) Tasks() []*Task
- func (p *Plan) Validate() error
- type PlanConfig
- type PlanOption
- type PlanSummary
- type Report
- type Result
- type Results
- type RetryOption
- type Status
- type StepSummary
- type Task
- func (t *Task) Dependencies() []*Task
- func (t *Task) DependsOn(deps ...*Task) *Task
- func (t *Task) ErrorStrategy() *ErrorStrategy
- func (t *Task) Fn() TaskFn
- func (t *Task) Guard() GuardFn
- func (t *Task) GuardReason() string
- func (t *Task) IsFunc() bool
- func (t *Task) Name() string
- func (t *Task) OnError(strategy ErrorStrategy)
- func (t *Task) OnlyIfChanged()
- func (t *Task) RequiresChange() bool
- func (t *Task) SetGuardReason(reason string)
- func (t *Task) SetName(name string)
- func (t *Task) When(fn GuardFn)
- func (t *Task) WhenWithReason(fn GuardFn, reason string)
- type TaskFn
- type TaskFnWithResults
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
var Continue = ErrorStrategy{/* contains filtered or unexported fields */}
Continue skips dependents of the failed task but continues independent tasks.
var StopAll = ErrorStrategy{/* contains filtered or unexported fields */}
StopAll cancels all remaining tasks on first failure.
Functions ¶
func StructToMap ¶
StructToMap converts a struct to map[string]any using its JSON tags. Returns nil if v is nil or cannot be marshaled.
Types ¶
type ErrorStrategy ¶
type ErrorStrategy struct {
// contains filtered or unexported fields
}
ErrorStrategy defines how the runner handles task failures.
func Retry ¶
func Retry( n int, opts ...RetryOption, ) ErrorStrategy
Retry returns a strategy that retries a failed task n times before failing. Options configure backoff behavior.
func (ErrorStrategy) RetryCount ¶
func (e ErrorStrategy) RetryCount() int
RetryCount returns the number of retries for this strategy.
func (ErrorStrategy) String ¶
func (e ErrorStrategy) String() string
String returns a human-readable representation of the strategy.
type Hooks ¶
type Hooks struct {
BeforePlan func(summary PlanSummary)
AfterPlan func(report *Report)
BeforeLevel func(level int, tasks []*Task, parallel bool)
AfterLevel func(level int, results []TaskResult)
BeforeTask func(task *Task)
AfterTask func(task *Task, result TaskResult)
OnRetry func(task *Task, attempt int, err error)
OnSkip func(task *Task, reason string)
}
Hooks provides consumer-controlled callbacks for plan execution events. All fields are optional — nil callbacks are skipped. The SDK performs no logging; hooks are the only output mechanism.
type HostResult ¶
type HostResult struct {
Hostname string
Status string
Changed bool
Error string
Data map[string]any
JobDuration time.Duration
}
HostResult represents a single host's response within a broadcast operation.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan is a DAG of tasks with dependency edges.
func NewPlan ¶
func NewPlan( client *osapiclient.Client, opts ...PlanOption, ) *Plan
NewPlan creates a new plan bound to an OSAPI client.
func (*Plan) Client ¶
func (p *Plan) Client() *osapiclient.Client
Client returns the OSAPI client bound to this plan.
func (*Plan) Explain ¶
Explain returns a human-readable representation of the execution plan showing levels, parallelism, dependencies, and guards.
func (*Plan) Levels ¶
Levels returns the levelized DAG -- tasks grouped into execution levels where all tasks in a level can run concurrently. Returns an error if the plan fails validation.
func (*Plan) TaskFuncWithResults ¶
func (p *Plan) TaskFuncWithResults( name string, fn TaskFnWithResults, ) *Task
TaskFuncWithResults creates a functional task that receives completed results from prior tasks, adds it to the plan, and returns it.
type PlanConfig ¶
type PlanConfig struct {
OnErrorStrategy ErrorStrategy
Hooks *Hooks
}
PlanConfig holds plan-level configuration.
type PlanOption ¶
type PlanOption func(*PlanConfig)
PlanOption is a functional option for NewPlan.
func OnError ¶
func OnError( strategy ErrorStrategy, ) PlanOption
OnError returns a PlanOption that sets the default error strategy.
func WithHooks ¶
func WithHooks( hooks Hooks, ) PlanOption
WithHooks attaches lifecycle callbacks to plan execution.
type PlanSummary ¶
type PlanSummary struct {
TotalTasks int
Steps []StepSummary
}
PlanSummary describes the execution plan before it runs.
type Report ¶
type Report struct {
Tasks []TaskResult
Duration time.Duration
}
Report is the aggregate output of a plan execution.
type Result ¶
type Result struct {
JobID string
Changed bool
Data map[string]any
Status Status
JobDuration time.Duration
HostResults []HostResult
}
Result is the outcome of a single task execution.
func CollectionResult ¶
func CollectionResult[T any]( col client.Collection[T], rawJSON []byte, toHostResult func(T) HostResult, ) (*Result, error)
CollectionResult builds a Result from a Collection response. It iterates all results, applies the toHostResult mapper to build per-host details, and auto-populates HostResult.Data via StructToMap when the mapper leaves it nil. Changed is true if any host reported a change.
When rawJSON is non-nil, it is unmarshaled into Result.Data to provide the full response for downstream consumers (e.g., guards or Results.Decode). Pass resp.RawJSON() for this, or nil to skip.
type RetryOption ¶
type RetryOption func(*ErrorStrategy)
RetryOption configures retry behavior.
func WithRetryBackoff ¶
func WithRetryBackoff( initial time.Duration, maxInterval time.Duration, ) RetryOption
WithRetryBackoff enables exponential backoff between retry attempts with the given initial and maximum intervals.
type Status ¶
type Status string
Status represents the outcome of a task execution.
const ( // StatusPending and StatusRunning are reserved for future // streaming status support. The runner does not currently // assign these — tasks go directly to a terminal status. StatusPending Status = "pending" StatusRunning Status = "running" StatusChanged Status = "changed" StatusUnchanged Status = "unchanged" StatusSkipped Status = "skipped" StatusFailed Status = "failed" )
Task execution statuses.
type StepSummary ¶
StepSummary describes a single execution step (DAG level).
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task is a unit of work in an orchestration plan.
func NewTaskFunc ¶
NewTaskFunc creates a functional task with custom logic.
func NewTaskFuncWithResults ¶
func NewTaskFuncWithResults( name string, fn TaskFnWithResults, ) *Task
NewTaskFuncWithResults creates a functional task that receives completed results from prior tasks.
func (*Task) Dependencies ¶
Dependencies returns the task's dependencies.
func (*Task) ErrorStrategy ¶
func (t *Task) ErrorStrategy() *ErrorStrategy
ErrorStrategy returns the per-task error strategy, or nil to use the plan default.
func (*Task) GuardReason ¶
GuardReason returns the current guard reason.
func (*Task) OnError ¶
func (t *Task) OnError( strategy ErrorStrategy, )
OnError sets a per-task error strategy override.
func (*Task) OnlyIfChanged ¶
func (t *Task) OnlyIfChanged()
OnlyIfChanged marks this task to only run if at least one dependency reported Changed=true.
func (*Task) RequiresChange ¶
RequiresChange returns true if OnlyIfChanged was set.
func (*Task) SetGuardReason ¶
SetGuardReason updates the skip reason shown when the guard returns false. Use inside a guard function to provide a dynamic reason based on runtime conditions.
func (*Task) When ¶
When sets a custom guard function that determines whether this task should execute.
func (*Task) WhenWithReason ¶
WhenWithReason sets a guard with a custom skip reason shown when the guard returns false.
type TaskFn ¶
TaskFn is the signature for functional tasks. The client parameter provides access to the OSAPI SDK for making API calls.
type TaskFnWithResults ¶
type TaskFnWithResults func( ctx context.Context, client *osapiclient.Client, results Results, ) (*Result, error)
TaskFnWithResults is like TaskFn but receives completed task results for inter-task data access.