Documentation
¶
Overview ¶
Package automation is the engine that plans and runs workflows over units.
Index ¶
- Constants
- Variables
- type CheckOpts
- type Deferred
- type Dueer
- type Engine
- func (e *Engine) Act(ctx context.Context, id string, a workflow.Action, guidance string) (_ workflow.Item, err error)
- func (e *Engine) Drop(ctx context.Context, u unit.Unit, why string) error
- func (e *Engine) Due() time.Time
- func (e *Engine) DueRun(ctx context.Context) (err error)
- func (e *Engine) Evaluate(ctx context.Context, t workflow.TriggerKind) (Plan, error)
- func (e *Engine) Pending(ctx context.Context) ([]workflow.Item, error)
- func (e *Engine) Seen() port.Generation
- func (e *Engine) Sweep(ctx context.Context, loop sync.Locker) (summary, skipped string, err error)
- type Events
- type Filter
- type Freshener
- type Gainer
- type Guidance
- type Ledger
- type Marks
- type Owner
- type Pause
- type Plan
- type PlanWrite
- type ProposedDraft
- type Refresher
- type Refused
- type RunOpts
- type Scoper
- type Seener
- type Settler
- type State
- type StateLoader
- type Steps
- type Transient
- type Units
- type Withdrawals
Constants ¶
const DefaultRetryBase = time.Minute
DefaultRetryBase is the first retry delay of a failed step when RetryBase is zero.
const Revalidate = port.TopicPRs | port.TopicSourceEvents | port.TopicTurns | port.TopicOverrides
Revalidate are the topics whose notes after a plan's generation drop the plan's run items on the noted units: the base sweep's set.
Variables ¶
var ErrUnitGone = errors.New("unit gone")
ErrUnitGone is what Units.Facts returns, wrapped or not, for a unit that no longer exists: an event of that unit is passed instead of held.
Functions ¶
This section is empty.
Types ¶
type Deferred ¶
type Deferred struct{ Reason string }
Deferred is a step started asynchronously: the item stays pending until a later Run returns done.
type Engine ¶
type Engine struct {
Workflows func() []workflow.Workflow
// Broken names the workflows that failed to load; their proposed drafts
// stay until they load again or are gone. Nil: none failed.
Broken func() []string
Units Units
Events Events
Steps Steps
Ledger Ledger
Guidance Guidance
Changes port.Changes // the wake (TopicSourceEvents for event workflows) and the revalidation under the lock
Clock port.Clock
Codecs *unit.Registry
Pause func(ctx context.Context) (Pause, error)
Config func() workflow.Facts
State StateLoader
Marks Marks // nil reads every unit as having no marks
// Withdrawals are the drafts the workflows proposed; nil withdraws none.
Withdrawals Withdrawals
// PluginEnabled says whether a provider's plugin is on; nil: every one
// is. No draft of a disabled plugin's unit is withdrawn.
PluginEnabled func(unit.ProviderID) bool
Reachable func(ctx context.Context) error
RetryBase time.Duration
Pub port.Publisher
Log func(format string, args ...any)
// contains filtered or unexported fields
}
func (*Engine) Act ¶
func (e *Engine) Act(ctx context.Context, id string, a workflow.Action, guidance string) (_ workflow.Item, err error)
Act carries the user's action on a plan item; the caller holds the loop lock. Apply runs the item by hand: the visible default is lifted, the guards hold, and a blocked item's attempts start over. Guide runs it at once with the guidance. Skip and dismiss are terminal for the item's key.
func (*Engine) Drop ¶
Drop discards u's pending items without marking their keys: the next evaluation plans them again if they still match.
func (*Engine) Due ¶
Due is the earliest instant after the last sweep at which a decision changes with no input changing: a pending deadline, a retry time, the next schedule firing, or a facts provider's own deadline. Zero when none.
func (*Engine) DueRun ¶
DueRun runs the pending items whose window ended with default run; the caller holds the loop lock.
func (*Engine) Evaluate ¶
Evaluate plans the workflows of trigger t, or of every trigger when t is empty. It reads the ledger and the facts providers only: it writes nothing, notes nothing, spends no budget and consumes no guidance.
func (*Engine) Pending ¶
Pending are the pending items of every workflow; the composition root picks the turn.start ones for the read model.
func (*Engine) Seen ¶
func (e *Engine) Seen() port.Generation
Seen is the workspace snapshot generation the last sweep read.
func (*Engine) Sweep ¶
Sweep implements daemon.Sweeper. Without the loop lock it checks the manager is reachable, refreshes the facts providers, evaluates every trigger, saves the plan, advances the event cursors and drops the run items whose source moved. Under the lock it drops the run items whose unit was noted after the plan's generation and no longer match, notes the refusals, runs the run items and the due pending ones, withdraws the drafts the workflows no longer call for, and settles.
type Events ¶
type Events interface {
Since(ctx context.Context, cursor int64, kinds []string) ([]workflow.Event, error)
Head(ctx context.Context) (int64, error)
Cursor(ctx context.Context, workflow string) (cursor int64, lastFire time.Time, ok bool, err error)
Advance(ctx context.Context, workflow string, cursor int64, lastFire time.Time) error
}
Events are the durable events event workflows read, and each workflow's cursor.
type Freshener ¶
Freshener is an optional capability of Units, asked before the loop lock: the units whose source object moved since their facts were read.
type Gainer ¶
Gainer is an optional capability of Units: what acting on a unit frees, read for items only.
type Guidance ¶
type Guidance interface {
Peek(ctx context.Context, u unit.Unit) (string, error)
Take(ctx context.Context, u unit.Unit) (string, error)
// Keep stores guidance a run took and did not use, unless newer guidance is stored.
Keep(ctx context.Context, u unit.Unit, guidance string) error
}
Guidance is the user's stored guidance for a unit's next turn.
type Ledger ¶
type Ledger interface {
// Save replaces the items of p's workflows, leaving out, in the same
// write, an item whose key is done or dismissed: a writer that planned
// before a run or a dismiss never brings the item back. It notes
// TopicGate only when the pending set changes.
Save(ctx context.Context, p PlanWrite, evs ...port.Event) error
Items(ctx context.Context, f Filter) ([]workflow.Item, error)
Run(ctx context.Context, k workflow.Key) (workflow.Run, bool, error)
Record(ctx context.Context, r workflow.Run, it workflow.Item, evs ...port.Event) error
Count(ctx context.Context, workflow string, since time.Time, u *unit.Unit) (int, error)
}
Ledger stores the plan and the runs. Recording a done or dismissed run also sets the item's Marks on its unit, in the same write.
type Marks ¶ added in v0.2.0
Marks are what a unit's triggers already handled, by mark name, which a workflow's handled() reads.
type Owner ¶ added in v0.2.0
Owner is an optional capability of Units: the units of work a subject belongs to, whose timelines show the steps run on it. None keeps them on the subject.
type Plan ¶
type Plan struct {
Items []workflow.Item
Errors []string
Gen port.Generation // the change log generation the evaluation read at
}
type ProposedDraft ¶ added in v0.2.0
ProposedDraft is an open draft a workflow proposed: the subject it was proposed on and the draft slot's facts ("draft.person_waited", ...).
type Refresher ¶
Refresher is an optional capability of Units: the provider's own writes (keeping idle periods, registering terminals, census marks), run by Sweep only, before Evaluate.
type Refused ¶
type Refused struct{ Reason string }
Refused is a guard refusing at run time: the item is blocked and re-evaluated, its attempts untouched.
type Scoper ¶ added in v0.2.0
type Scoper interface {
Scope(ctx context.Context, workflow string, u unit.Unit, f workflow.Facts) (workflow.Facts, error)
}
Scoper is an optional capability of Units: the facts of u that depend on the workflow reading them, such as the settlement of the drafts it proposed, laid over the unit's facts f. It returns a new map and never writes f, which the other workflows read.
type Seener ¶
type Seener interface {
Seen() port.Generation
}
Seener is an optional capability of Units: the generation of the workspace snapshot its facts came from.
type Settler ¶
Settler is an optional capability of Units: planning bookkeeping, run by an applying Sweep only, after the steps.
type Steps ¶
type Steps interface {
// Check is pure: no store write, no note, no brief request, no network.
Check(ctx context.Context, st workflow.Step, u unit.Unit, why workflow.Why, o CheckOpts) (refusal string, err error)
// Note writes what a refusal records (brief request and brief_waiting;
// round_held and MarkUnread on a cap's first hit; the daily fetch); an
// applying Sweep only.
Note(ctx context.Context, st workflow.Step, u unit.Unit, why workflow.Why, refusal string) error
// Run must be idempotent per item key: a retry runs the item's steps from the first.
Run(ctx context.Context, st workflow.Step, u unit.Unit, why workflow.Why, o RunOpts) (detail string, err error)
// Dismiss writes the step's "handled until something new" records and its event.
Dismiss(ctx context.Context, st workflow.Step, u unit.Unit, why workflow.Why) error
}
Steps run the builtin steps a workflow names.
type Transient ¶
type Transient struct{ Err error }
Transient is a failure worth retrying (manager unreachable, context ended, GitHub budget): attempts untouched.
type Units ¶
type Units interface {
List(ctx context.Context, p unit.ProviderID) ([]unit.Unit, error)
Facts(ctx context.Context, u unit.Unit) (workflow.Facts, error)
}
Units is a unit provider: the units it holds and each unit's facts.
type Withdrawals ¶ added in v0.2.0
type Withdrawals interface {
// Proposed are the proposed drafts of workflow; "" lists every
// workflow's.
Proposed(ctx context.Context, workflow string) ([]ProposedDraft, error)
// Withdraw discards the draft, Reason reason; a draft no longer open is
// left as it is.
Withdraw(ctx context.Context, id int64, reason string) error
}
Withdrawals are the open drafts a workflow proposed, which the sweep withdraws when the workflow's [drafts.withdraw] when matches one, or when the workflow is no longer loaded; never those of a disabled plugin's units.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package automationtest holds in-memory fakes of the engine's ports and the contract suites every implementation runs.
|
Package automationtest holds in-memory fakes of the engine's ports and the contract suites every implementation runs. |