Documentation
¶
Overview ¶
Package scheduler fires flows on cron schedules and one-shot times (backlog AO-028) — the basis for "assign and walk away" and recurring digests.
Index ¶
- func NextFire(definition Definition, after time.Time) (time.Time, error)
- func OccurrenceID(scheduleID string, scheduledFor time.Time) string
- type Definition
- type DurableScheduler
- type Kind
- type Occurrence
- type OccurrenceState
- type Repository
- type Scheduler
- func (s *Scheduler) Cron(spec string, fn func()) (cron.EntryID, error)
- func (s *Scheduler) CronScheduled(spec string, fn func(time.Time)) (cron.EntryID, error)
- func (s *Scheduler) Once(d time.Duration, fn func()) error
- func (s *Scheduler) OnceAt(at time.Time, fn func()) error
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Definition ¶ added in v0.13.0
type Definition struct {
ID string `json:"id"`
Title string `json:"title"`
Kind Kind `json:"kind"`
Expression string `json:"expression"`
FlowID string `json:"flow_id"`
Timezone string `json:"timezone"`
Enabled bool `json:"enabled"`
NextFireAt time.Time `json:"next_fire_at,omitempty"`
LastFireAt time.Time `json:"last_fire_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type DurableScheduler ¶ added in v0.13.0
type DurableScheduler struct {
// contains filtered or unexported fields
}
func NewDurableScheduler ¶ added in v0.13.0
func NewDurableScheduler(repository Repository, trigger Trigger, displayLocation *time.Location) *DurableScheduler
func (*DurableScheduler) Create ¶ added in v0.13.0
func (s *DurableScheduler) Create(ctx context.Context, definition Definition) (Definition, error)
Create persists and hot-registers a definition in the running daemon.
func (*DurableScheduler) Definitions ¶ added in v0.13.0
func (s *DurableScheduler) Definitions(context.Context) ([]Definition, error)
func (*DurableScheduler) Start ¶ added in v0.13.0
func (s *DurableScheduler) Start(ctx context.Context) error
Start reloads durable definitions before the in-process clock begins.
func (*DurableScheduler) Stop ¶ added in v0.13.0
func (s *DurableScheduler) Stop()
Stop joins active callbacks and permanently closes this manager. A daemon restart constructs a fresh manager from the durable repository.
type Occurrence ¶ added in v0.13.0
type Occurrence struct {
ID string `json:"id"`
ScheduleID string `json:"schedule_id"`
RunID string `json:"run_id,omitempty"`
ScheduledFor time.Time `json:"scheduled_for"`
State OccurrenceState `json:"state"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func OccurrencesForDay ¶ added in v0.13.0
func OccurrencesForDay(definition Definition, day time.Time, viewerLocation *time.Location) ([]Occurrence, error)
OccurrencesForDay expands one durable definition into real occurrences whose instants fall inside the requested viewer-local calendar day.
type OccurrenceState ¶ added in v0.13.0
type OccurrenceState string
const ( OccurrenceScheduled OccurrenceState = "scheduled" OccurrenceFired OccurrenceState = "fired" OccurrenceRunning OccurrenceState = "running" OccurrenceSucceeded OccurrenceState = "succeeded" OccurrenceFailed OccurrenceState = "failed" OccurrenceCanceled OccurrenceState = "canceled" )
type Repository ¶ added in v0.13.0
type Repository interface {
CreateSchedule(Definition) error
ListSchedules() ([]Definition, error)
UpsertScheduleOccurrence(Occurrence) error
TransitionScheduleOccurrence(id string, from, to OccurrenceState, runID, errorMessage string) (bool, error)
UpdateScheduleFire(id string, lastFireAt, nextFireAt time.Time) error
}
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs cron and one-shot triggers.
func (*Scheduler) Cron ¶
Cron registers a recurring trigger. spec is a 6-field cron (with seconds), e.g. "0 0 9 * * *" for 09:00 daily, or "@every 1h".
func (*Scheduler) CronScheduled ¶ added in v1.0.4
CronScheduled registers a recurring trigger and reports the occurrence time planned by the cron clock, even when its callback starts late.
type Trigger ¶ added in v0.13.0
type Trigger func(context.Context, Definition, Occurrence) error