automation

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package automation is the engine that plans and runs workflows over units.

Index

Constants

View Source
const DefaultRetryBase = time.Minute

DefaultRetryBase is the first retry delay of a failed step when RetryBase is zero.

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

View Source
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 CheckOpts

type CheckOpts struct {
	Observe bool
	ByHand  bool
}

type Deferred

type Deferred struct{ Reason string }

Deferred is a step started asynchronously: the item stays pending until a later Run returns done.

func (Deferred) Error

func (d Deferred) Error() string

type Dueer

type Dueer interface {
	Due() time.Time
}

Dueer is an optional capability of Units: the provider's own next deadline.

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

func (e *Engine) Drop(ctx context.Context, u unit.Unit, why string) error

Drop discards u's pending items without marking their keys: the next evaluation plans them again if they still match.

func (*Engine) Due

func (e *Engine) Due() time.Time

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

func (e *Engine) DueRun(ctx context.Context) (err error)

DueRun runs the pending items whose window ended with default run; the caller holds the loop lock.

func (*Engine) Evaluate

func (e *Engine) Evaluate(ctx context.Context, t workflow.TriggerKind) (Plan, error)

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

func (e *Engine) Pending(ctx context.Context) ([]workflow.Item, error)

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

func (e *Engine) Sweep(ctx context.Context, loop sync.Locker) (summary, skipped string, err error)

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 Filter

type Filter struct {
	Workflow  string
	Provider  unit.ProviderID
	Unit      *unit.Unit
	Decisions []workflow.Decision
	ID        string
}

type Freshener

type Freshener interface {
	Moved(ctx context.Context, units []unit.Unit) ([]unit.Unit, error)
}

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

type Gainer interface {
	Gain(ctx context.Context, u unit.Unit) (workflow.Gain, error)
}

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

type Marks interface {
	Marks(ctx context.Context, u unit.Unit) (map[string]string, error)
}

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

type Owner interface {
	Owners(ctx context.Context, u unit.Unit) ([]unit.Unit, error)
}

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 Pause

type Pause struct {
	On    bool
	Repos []string // owner/repo
}

Pause holds every unit when On, else the units of the repositories in Repos.

type Plan

type Plan struct {
	Items  []workflow.Item
	Errors []string
	Gen    port.Generation // the change log generation the evaluation read at
}

type PlanWrite

type PlanWrite struct {
	Workflows []string
	Items     []workflow.Item
}

type ProposedDraft added in v0.2.0

type ProposedDraft struct {
	ID       int64
	Workflow string
	Subject  unit.Unit
	Facts    workflow.Facts
}

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

type Refresher interface {
	Refresh(ctx context.Context) error
}

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.

func (Refused) Error

func (r Refused) Error() string

type RunOpts

type RunOpts struct {
	Guidance          string
	ByHand, Confirmed bool
}

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

type Settler interface {
	Settle(ctx context.Context, st State) error
}

Settler is an optional capability of Units: planning bookkeeping, run by an applying Sweep only, after the steps.

type State

type State interface {
	Save(ctx context.Context) error
}

State is the sweep's round state, opaque to the engine.

type StateLoader

type StateLoader interface {
	Load(ctx context.Context) (State, error)
}

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.

func (Transient) Error

func (t Transient) Error() string

func (Transient) Unwrap

func (t Transient) Unwrap() error

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL