automation

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package automation holds the scheduling rules of agent automations: when a trigger fires, and what an automation's run is told. It does no I/O.

Index

Constants

View Source
const DefaultMinInterval = 5 * time.Minute

DefaultMinInterval is the shortest gap allowed between two runs.

Variables

View Source
var ErrInvalidTrigger = errors.New("invalid trigger")

ErrInvalidTrigger wraps every trigger validation failure.

Functions

func RenderInstruction

func RenderInstruction(instruction string, v RunVars) string

RenderInstruction substitutes {{now}}, {{last_run_at}}, {{last_success_at}}, {{run_id}} and {{automation_name}}. Unknown placeholders are left alone so a literal "{{" in a prompt survives.

func RunNote

func RunNote(name string, scheduledAt time.Time, loc *time.Location) string

RunNote tells the agent it is running unattended, so it does not wait on a user who is not there.

func RunQuery

func RunQuery(instruction string, v RunVars, lastResult string) string

RunQuery is the user turn of one run: the rendered instruction, preceded by the previous run's answer when the automation carries it over.

Types

type RunVars

type RunVars struct {
	Now            time.Time
	LastRunAt      *time.Time
	LastSuccessAt  *time.Time
	RunID          string
	AutomationName string
	Location       *time.Location
}

RunVars are the values an instruction may reference.

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is a validated trigger.

func Parse

Parse validates t. A cron expression has five fields (minute first) or six (seconds first), or is a descriptor such as @daily; it is evaluated in t.Timezone, which a CRON_TZ= prefix in the expression may not override.

func (*Schedule) CheckInterval

func (s *Schedule) CheckInterval(from time.Time, minInterval time.Duration) error

CheckInterval rejects a cron trigger that can fire twice within min. It looks at the gaps over the next days, which catches expressions such as "* * * * *" and "*/2 9 * * *" alike.

func (*Schedule) Next

func (s *Schedule) Next(after time.Time) *time.Time

Next is the first time the trigger fires strictly after after, or nil when it never fires again.

func (*Schedule) Trigger

func (s *Schedule) Trigger() types.AutomationTrigger

Trigger is the normalized trigger.

func (*Schedule) Upcoming

func (s *Schedule) Upcoming(after time.Time, n int) []time.Time

Upcoming is the next n firing times after after.

Jump to

Keyboard shortcuts

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