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 ActorKind(actor string) string
- func ChainData(data string, c Chain) string
- func MarkNames(p Predicate) []string
- func Names(ctx context.Context, fact string) bool
- func OnlyReads(ctx context.Context, names ...string) context.Context
- func Reads(w Workflow) []string
- func ReadsMarks(ps ...Predicate) bool
- func ReadsOf(ctx context.Context) []string
- func Reason(key string, params map[string]string) string
- func ReasonOf(text string) (string, map[string]string, bool)
- func StepReads(steps []Step) []string
- func ValidApproval(m ApprovalMode, window time.Duration) error
- func WithReads(ctx context.Context, names ...string) context.Context
- type Action
- type Approval
- type ApprovalMode
- type ApprovalRule
- type AskData
- type Chain
- type Cron
- type Decision
- type Event
- type Fact
- type Facts
- type Gain
- type Item
- type Key
- type Limits
- type Outbox
- type Outcome
- type Predicate
- type Reach
- type Refused
- type Run
- type RunStatus
- type Step
- type Temporal
- type TemporalKind
- type Trigger
- type TriggerKind
- type Unrequested
- type Vars
- type Why
- type WithdrawRule
- type Workflow
Constants ¶
const ( DefaultChainDepth = 3 MaxChainDepth = 5 )
The bounds of a chain of workflows triggering each other.
const ( ReasonWaits = "waits for you" ReasonVisible = "a visible step waits for you" ReasonObserve = "observe mode" ReasonWindow = "runs when its window ends" ReasonGuided = "guided by you" ReasonPaused = "paused" ReasonHeld = "waits for you while {facts}" ReasonHeldRefused = "waits for you while {facts}: {refusal}" ReasonRetrying = "retrying after {error}" ReasonFailed = "failed {n} times: {error}" ReasonPerRun = "limit per_run {n} reached" ReasonPerDay = "limit per_day {n} reached" ReasonPerUnitDay = "limit per_unit_per_day {n} reached" ReasonCooling = "cooling down for {duration}" ReasonSincePaused = "paused since it was planned" ReasonSinceUnmatched = "it no longer matches since it was planned" ReasonSinceUnit = "its unit changed since it was planned" ReasonSinceWaits = "it waits for you since it was planned" ReasonSinceSource = "its source moved since it was planned" ReasonSinceLeft = "it left the plan since it was planned" ReasonSinceActed = "it was acted on since it was planned" ReasonSinceDone = "it was done since it was planned" ReasonSinceDismissed = "it was dismissed since it was planned" )
The reasons the engine gives a plan item, as templates whose {name} is a value the reason carries. Reason renders one for the ledger and the terminal; the cockpit words it through the catalog, whose key is the template, after ReasonOf reads it back.
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 EventIDFact = "trigger.event.id"
EventIDFact is the trigger fact an event workflow's key may name, so each event plans its own run.
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.
var Reasons = []string{ ReasonWaits, ReasonVisible, ReasonObserve, ReasonWindow, ReasonGuided, ReasonPaused, ReasonHeldRefused, ReasonHeld, ReasonRetrying, ReasonFailed, ReasonPerRun, ReasonPerDay, ReasonPerUnitDay, ReasonCooling, ReasonSincePaused, ReasonSinceUnmatched, ReasonSinceUnit, ReasonSinceWaits, ReasonSinceSource, ReasonSinceLeft, ReasonSinceActed, ReasonSinceDone, ReasonSinceDismissed, }
Reasons are the engine's reason templates, those carrying a refusal after those they extend, so ReasonOf tries the longer first.
Functions ¶
func ActorKind ¶ added in v0.3.0
ActorKind is the kind of actor an event's actor names, as "<kind>:<source>" writes it: "person" of "person:cockpit"; "" for an actor written otherwise.
func ChainData ¶ added in v0.3.0
ChainData is the stored data of an event that carries chain c: data itself for a zero chain.
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 Names ¶ added in v0.4.0
Names says whether the reads ctx carries name fact, as a fact name or inside a text that mentions it.
func Reads ¶ added in v0.4.0
Reads are the facts w reads: those of its when, withdraw and approval predicates, its key and marks, and every text of its steps' args and of its ask, any of which may name a fact.
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 Reason ¶ added in v0.4.0
Reason is template key with each {name} replaced by its value in params.
func ReasonOf ¶ added in v0.4.0
ReasonOf is the template text renders and the values it carries; false when no template renders it, as a refusal a step or a guard words itself.
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 ModeOf ¶ added in v0.3.0
func ModeOf(m gate.Mode) ApprovalMode
ModeOf is a gate's approval mode as a run's: send and run run it; dry_run, a draft gate's only, waits.
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 AskData ¶ added in v0.4.0
AskData is what a workflow's Ask renders: its unit as people read it and the unit's facts, by name.
type Chain ¶ added in v0.3.0
Chain is the chain of workflows an event closes: Depth is how many workflows ran one after the other to cause it, Workflows their names in order. A person's event starts none: its chain is zero.
func SplitChain ¶ added in v0.3.0
SplitChain reads stored event data as ChainData wrote it: the data and its chain, zero for data written with none.
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 Decision ¶
type Decision string
const ( DecisionRun Decision = "run" DecisionPending Decision = "pending" DecisionBlocked Decision = "blocked" DecisionSkipped Decision = "skipped" // DecisionDeferred is an item whose step started asynchronously: it runs // again at its Deadline until a run is done. No person decides it. DecisionDeferred Decision = "deferred" )
type Facts ¶
Facts are a unit's facts by dotted name; values are bool, int, string, []string, time.Duration or time.Time, or a Temporal a provider reports, which the engine resolves to one of those before a predicate reads it. "<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 Outbox ¶ added in v0.4.0
type Outbox struct {
Title, About string
}
Outbox is the head of a workflow's group of drafts in the Outbox: its title and one line on why the workflow drafts them.
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 Temporal ¶ added in v0.3.0
Temporal is a fact whose value changes with the clock, which a source reports instead of a value it would have to report again as time passes. The engine resolves it with its own clock whenever it reads the facts. A Temporal whose Time is zero resolves to its type's zero and has no deadline.
type TemporalKind ¶ added in v0.3.0
type TemporalKind int
TemporalKind is how a Temporal fact reads the clock.
const ( // TemporalSince is the duration from Time to now. TemporalSince TemporalKind = iota + 1 // TemporalAt is true from Time on. TemporalAt // TemporalAfter is true once more than Threshold has passed since // Time, counted in working days when WorkingDays. TemporalAfter )
type Trigger ¶
type Trigger struct {
Kind TriggerKind
On []string // event kinds, Kind == TriggerEvent
Schedule *Cron // Kind == TriggerSchedule
// Actors are the kinds of actor whose events plan the workflow, every
// one when empty; Depth the longest chain an event it reacts to may
// close, DefaultChainDepth when 0. Both read with Kind == TriggerEvent.
Actors []string
Depth int
}
type TriggerKind ¶
type TriggerKind string
const ( TriggerSweep TriggerKind = "sweep" TriggerEvent TriggerKind = "event" TriggerSchedule TriggerKind = "schedule" )
type Unrequested ¶ added in v0.4.0
type Unrequested struct{ Fact string }
Unrequested is the value of a costly fact whose reader did not name it (WithReads): evaluating it is an error, so a reader that forgot to name it fails instead of reading an empty value, and it prints as not requested.
func (Unrequested) MarshalJSON ¶ added in v0.4.0
func (u Unrequested) MarshalJSON() ([]byte, error)
func (Unrequested) String ¶ added in v0.4.0
func (u Unrequested) String() string
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
// LoadMarks reads Marks when Marks is nil, only once a predicate reaches a handled(); nil reads none.
LoadMarks func() (map[string]string, error)
Now time.Time
}
type WithdrawRule ¶ added in v0.4.0
WithdrawRule withdraws an open draft that matches When, with Reason.
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
// Off ships the workflow switched off: it plans nothing until the config's
// workflows.<name>.enabled turns it on.
Off 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 is the approval of its runs' plan gates.
Approval Approval
// Gates are the approval of the gates its gate.open steps open, by
// kind, every kind but draft and plan.
Gates map[gate.Kind]Approval
Source string // manifest path
Bundled bool
// Overrides are the files of a bundled workflow a user directory replaces.
Overrides []string
// DraftApproval is the approval of the drafts its steps and turns
// propose, from its [gates.approval]; nil when that names none for a
// draft gate.
DraftApproval *draft.Policy
// DraftsWait pins every draft the workflow proposes to wait for a person, whatever the configuration's
// approval says.
DraftsWait bool
// 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
// WithdrawRules are the manifest's [[drafts.withdraw.rule]], tried in order before Withdraw, each
// withdrawing with its own reason.
WithdrawRules []WithdrawRule
// GateWithdraw is the manifest's [gates.withdraw]: when an open gate its gate.open steps opened on a unit
// no longer stands, over the unit's facts, with the reason the withdrawal records. Nil withdraws none.
GateWithdraw *WithdrawRule
// Ask is what the plan gate of a run asks, over AskData; nil asks its Summary.
Ask *template.Template
// Outbox is how the Outbox names the group of the drafts the workflow proposed.
Outbox Outbox
}
func (Workflow) Asks ¶ added in v0.4.0
Asks is what the plan gate of w's run on the unit labelled label asks over its facts: its Ask, else its Summary.
func (Workflow) Visible ¶
Visible says whether a step of the workflow acts in the user's name where others see it.
func (Workflow) Withdrawals ¶ added in v0.4.0
func (w Workflow) Withdrawals() []WithdrawRule
Withdrawals are the rules w withdraws its open drafts by, in the order they are tried: its WithdrawRules, then Withdraw with WithdrawReason; none when it withdraws none.