Documentation
¶
Overview ¶
Package scheduler fires workflows whose trigger is "schedule" (internal/workflow.Trigger, ADR-0035) on their declared cron cadence, unattended — no HTTP request or CLI invocation supplies inputs or bindings the way a manual run does. It has two halves: Sync keeps the schedules table in step with whichever workflow version is currently installed, and Runner is the background loop that watches that table and calls runs.Execute once a row comes due.
Index ¶
Constants ¶
const ( // OnMissedSkip drops any backlog of occurrences the scheduler could not // fire while the agent was offline and resumes at the next future one. // It is the default a Trigger with an empty OnMissed gets. OnMissedSkip = "skip" // OnMissedFireOnce runs once for the most recently missed occurrence, // then resumes normal cadence. OnMissedFireOnce = "fire_once" )
Variables ¶
This section is empty.
Functions ¶
func NextRunAt ¶
NextRunAt returns the next time workflowID's schedule will fire, and false if it has no "schedule" trigger installed.
func Sync ¶
Sync brings the schedules table's row for def.ID in step with def's trigger: a "schedule" trigger upserts a row with a freshly computed next_run_at — installing a new version always reschedules from now, regardless of what an earlier version's cron was — and any other trigger deletes the row. Call it once per successful runs.InstallWorkflow (see internal/cli/workflow.go); def must already have passed workflow.Validate, so its cron expression (if any) is assumed well-formed.
Types ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner polls the schedules table and fires each row's workflow through runs.Execute once it comes due, the same run path internal/api's handleRunWorkflow and the CLI's `workflow run` use — a scheduled run is not a different kind of run, just a differently triggered one.
func NewRunner ¶
func NewRunner(db *sql.DB, executor runs.ActionExecutor, logger *slog.Logger, secretStore secrets.Store) *Runner
NewRunner builds a Runner. logger defaults to slog.Default() when nil, secretStore to secrets.EnvStore{} when nil — same default a directly built runs.ExecuteOptions{} falls back to, so a scheduled run resolves connector secrets exactly like a manual one unless the caller wires in the agent's configured secrets.MultiStore (internal/runtime.NewAgent).
func (*Runner) Run ¶
Run polls for due schedules immediately, then every pollInterval, until ctx is cancelled. It blocks until then, so callers run it in its own goroutine. ctx is also the context every fired run executes under — cancelling it (agent shutdown) cancels any scheduled run still in flight, exactly like a run started from an HTTP request (see internal/runtime.Agent's runCtx).