Documentation
¶
Overview ¶
Package cron registers and runs scheduled jobs alongside the app's HTTP surface. Jobs run bare — no middleware chain applies — but the scheduler publishes request-lifecycle events to trace.Bus so the dashboard shows each run like any other traced call.
Jobs are identified by name. Re-registering a name replaces the prior job (its history is dropped). Schedules use robfig cron 5-field syntax; @every and @hourly style descriptors are also accepted.
Index ¶
- type HandlerFunc
- type Job
- type RunRecord
- type Scheduler
- func (s *Scheduler) Register(j Job) error
- func (s *Scheduler) SetPaused(name string, paused bool) bool
- func (s *Scheduler) Snapshot(name string) (Snapshot, bool)
- func (s *Scheduler) Snapshots() []Snapshot
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- func (s *Scheduler) Trigger(name string) bool
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
HandlerFunc is the user-supplied work. Return an error to mark the run failed; it surfaces on the dashboard and the next scheduled tick still fires.
type Job ¶
type Job struct {
Name string
Schedule string
Description string
Service string
Handler HandlerFunc
}
Job is the user-facing registration value. Service is optional — when set, the dashboard can group crons under the service node.
type RunRecord ¶
type RunRecord struct {
Started time.Time `json:"started"`
DurationMs int64 `json:"durationMs"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Manual bool `json:"manual,omitempty"`
}
RunRecord is one execution's outcome.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler owns the underlying cron and the set of registered jobs. One per App; safe for concurrent use.
func NewScheduler ¶
NewScheduler builds a Scheduler. historyCap is the per-job run buffer; pass 0 for the default of 20.
func (*Scheduler) Register ¶
Register adds or replaces a job. If the scheduler has already been Started, the job is scheduled immediately; otherwise it schedules on Start.
func (*Scheduler) SetPaused ¶
SetPaused toggles the pause bit on a job. Paused jobs still appear in the snapshot (with Paused: true) but the scheduler skips their tick fires. Manual Trigger bypasses the pause flag on purpose — operators often pause to then run ad-hoc.
func (*Scheduler) Snapshots ¶
Snapshots returns the current view of every registered job, sorted by name.
func (*Scheduler) Start ¶
func (s *Scheduler) Start()
Start begins dispatching ticks. Safe to call once; subsequent calls no-op.
type Snapshot ¶
type Snapshot struct {
Name string `json:"name"`
Schedule string `json:"schedule"`
Description string `json:"description,omitempty"`
Service string `json:"service,omitempty"`
Paused bool `json:"paused"`
Running bool `json:"running"`
NextRun *time.Time `json:"nextRun,omitempty"`
LastRun *RunRecord `json:"lastRun,omitempty"`
History []RunRecord `json:"history,omitempty"`
}
Snapshot is the serializable view the dashboard reads.