Documentation
¶
Overview ¶
Package workflow holds a parsed workflow and what the engine plans from it: triggers, reach, plan items, runs and their idempotency keys.
Index ¶
- Constants
- Variables
- func MarkNames(p Predicate) []string
- func ReadsMarks(ps ...Predicate) bool
- func ValidApproval(m ApprovalMode, window time.Duration) error
- type Action
- type Approval
- type ApprovalMode
- type ApprovalRule
- type Cron
- type Decision
- type Event
- type Fact
- type Facts
- type Gain
- type Item
- type Key
- type Limits
- type Outcome
- type Predicate
- type Reach
- type Refused
- type Run
- type RunStatus
- type Step
- type Trigger
- type TriggerKind
- type Vars
- type Why
- type Workflow
Constants ¶
const ( KindPlanned = "workflow_planned" // Key item id:decision, Data reason KindStepRan = "workflow_step_ran" // Key item id:step index KindStepRefused = "workflow_refused" // Key item id:attempt KindStepFailed = "workflow_failed" // Key item id:attempt KindItemDismissed = "workflow_dismissed" // Key item id KindItemDropped = "workflow_dropped" // Key item id:at, Data why )
const MaxAttempts = 3
MaxAttempts is how many failed runs make an item's key terminal.
Variables ¶
var ApprovalModes = []ApprovalMode{ApprovalRun, ApprovalDelay, ApprovalWait}
ApprovalModes are the run approval's modes.
var EngineKinds = []string{KindPlanned, KindStepRan, KindStepRefused, KindStepFailed, KindItemDismissed, KindItemDropped}
EngineKinds are the engine's own event kinds; a workflow's `on` may not name them.
var ErrWindow = errors.New("window is read only with mode delay, which needs one longer than zero")
ErrWindow refuses a window off the delay mode, or a delay with none.
Functions ¶
func MarkNames ¶ added in v0.2.0
MarkNames are the marks p reads with handled(); a predicate lists them through a MarkNames() []string method.
func ReadsMarks ¶ added in v0.2.0
ReadsMarks says whether one of ps reads the unit's marks, so a caller loads them only then.
func ValidApproval ¶ added in v0.2.0
func ValidApproval(m ApprovalMode, window time.Duration) error
ValidApproval refuses a mode outside ApprovalModes and a window off delay.
Types ¶
type Approval ¶
type Approval struct {
Mode ApprovalMode
Window time.Duration
Rules []ApprovalRule
}
Approval is a workflow's run approval: the first rule whose When holds, else Mode and Window.
func (Approval) Predicates ¶ added in v0.2.0
Predicates are a's rules' whens.
type ApprovalMode ¶ added in v0.2.0
type ApprovalMode string
ApprovalMode is how a workflow's matched item runs: at once, when its window ends unless a person stops it, or when a person applies it.
const ( ApprovalRun ApprovalMode = "run" ApprovalDelay ApprovalMode = "delay" ApprovalWait ApprovalMode = "wait" )
func (ApprovalMode) Releases ¶ added in v0.2.0
func (m ApprovalMode) Releases() bool
Releases says whether m runs an item with no person applying it.
type ApprovalRule ¶ added in v0.2.0
type ApprovalRule struct {
When Predicate
Mode ApprovalMode
Window time.Duration
}
ApprovalRule is one [[approval.rule]]: its mode and window when its When holds. A matched wait rule also makes pending an item a guard refuses.
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron is a five-field schedule ("0 9 * * 1-5") read in the location of the time it is asked about. When both day fields are restricted, a day matches either, as in cron(8).
type Facts ¶
Facts are a unit's facts by dotted name; values are bool, int, string, []string, time.Duration or time.Time. "<slot>.repo" is "owner/repo" or "" and is what the pause's Repos reads.
type Item ¶
type Item struct {
ID string
Key Key
Workflow string
Unit unit.Unit
Decision Decision
Reason string
Steps []Step
Gain Gain
Why Why
Default Outcome
Deadline time.Time
Guidance string // set by Act(guide) only
// Marks are the marks a done or dismissed run records, by full name, from
// the facts the item was planned with.
Marks map[string]mark.Value
Attempts int
Error string
Observe bool
At time.Time
}
type Key ¶
type Key struct {
Workflow string
Unit unit.Unit
Value string // sha256 hex of the sorted key values, first 16 chars
}
Key is the idempotency key: workflow, unit and the key facts' values (for a schedule trigger, plus the firing time).
type Outcome ¶
type Outcome string
Outcome is what a pending item does when its window ends unanswered.
type Refused ¶
type Refused struct{ Err error }
Refused is a predicate that never matches and says why on every match.
type Trigger ¶
type Trigger struct {
Kind TriggerKind
On []string // event kinds, Kind == TriggerEvent
Schedule *Cron // Kind == TriggerSchedule
}
type TriggerKind ¶
type TriggerKind string
const ( TriggerSweep TriggerKind = "sweep" TriggerEvent TriggerKind = "event" TriggerSchedule TriggerKind = "schedule" )
type Vars ¶
type Vars struct {
Facts Facts // the unit's slot ("pr.state", "session.idle_for")
Trigger Facts // "trigger.kind", "trigger.event.kind", "trigger.event.key", "trigger.event.data", "trigger.fired_at"
Config Facts // "config.cleanup.idle", ...
Marks map[string]string // the unit's handled marks by name, which handled() reads
Now time.Time
}
type Workflow ¶
type Workflow struct {
Name, Summary string
Provider unit.ProviderID
Slot string // the provider's fact slot: "pr" for github, else the provider id
Trigger Trigger
When Predicate
Steps []Step
Limits Limits
// Observe plans items pending and never runs them by itself.
Observe bool
Order int
Key []string // fact names; empty means the slot's fingerprint fact
// Marks are the facts whose values a done or dismissed item records as
// the unit's marks, by the mark's name under the workflow (mark.Of).
Marks map[string]string
Approval Approval
Source string // manifest path
Bundled bool
// Overrides are the files of a bundled workflow a user directory replaces.
Overrides []string
// DraftApproval is the manifest's [drafts.approval] block; nil when absent.
DraftApproval *draft.Policy
// Withdraw is the manifest's [drafts.withdraw] when, over the subject's facts
// and each draft's (the draft slot): an open draft the workflow proposed
// is withdrawn when it matches. Nil withdraws none.
Withdraw Predicate
// WithdrawReason is the Reason of a draft Withdraw withdraws: assigned
// or moot.
WithdrawReason string
}