Documentation
¶
Index ¶
- func DefaultScheduleFor(name string) string
- func DefaultTimeoutFor(name string) time.Duration
- func KnownTaskNames() map[string]bool
- type ExecutionRecord
- type HistoryWriter
- type Scheduler
- func (s *Scheduler) AddOrUpdateTask(task Task) error
- func (s *Scheduler) GetDefaults() []Task
- func (s *Scheduler) GetTaskStatuses() []TaskStatus
- func (s *Scheduler) RemoveTask(name string)
- func (s *Scheduler) RunTaskNow(name string) (*ExecutionRecord, error)
- func (s *Scheduler) StartWith(tasks []Task, overrides map[string]TaskOverride, history HistoryWriter)
- func (s *Scheduler) Stop()
- type Task
- type TaskOverride
- type TaskStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultScheduleFor ¶ added in v0.0.10
DefaultScheduleFor returns the default schedule for a task name, or empty string.
func DefaultTimeoutFor ¶ added in v0.0.10
DefaultTimeoutFor returns the default timeout for a task name.
func KnownTaskNames ¶ added in v0.0.10
KnownTaskNames returns the set of valid task names.
Types ¶
type ExecutionRecord ¶ added in v0.0.10
type ExecutionRecord struct {
ID int64 `json:"id"`
TaskName string `json:"task_name"`
StartedAt int64 `json:"started_at"`
FinishedAt int64 `json:"finished_at"`
DurationMs int64 `json:"duration_ms"`
Status string `json:"status"` // "success" or "error"
Error string `json:"error"`
Output string `json:"output"`
}
ExecutionRecord is a single task execution result.
type HistoryWriter ¶ added in v0.0.10
type HistoryWriter interface {
InsertHistory(ctx context.Context, rec *ExecutionRecord) error
CleanOldHistory(ctx context.Context, maxAge time.Duration) error
}
HistoryWriter persists execution records. Implemented by the store layer.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs periodic tasks.
func (*Scheduler) AddOrUpdateTask ¶ added in v0.0.10
AddOrUpdateTask removes an existing cron entry (if any) and adds a new one.
func (*Scheduler) GetDefaults ¶ added in v0.0.10
GetDefaults returns the original default task definitions.
func (*Scheduler) GetTaskStatuses ¶ added in v0.0.10
func (s *Scheduler) GetTaskStatuses() []TaskStatus
GetTaskStatuses returns the current status of all known tasks.
func (*Scheduler) RemoveTask ¶ added in v0.0.10
RemoveTask removes a task's cron entry by name.
func (*Scheduler) RunTaskNow ¶ added in v0.0.10
func (s *Scheduler) RunTaskNow(name string) (*ExecutionRecord, error)
RunTaskNow manually triggers a task by name.
func (*Scheduler) StartWith ¶ added in v0.0.10
func (s *Scheduler) StartWith(tasks []Task, overrides map[string]TaskOverride, history HistoryWriter)
StartWith begins all scheduled tasks with DB overrides and execution tracking.
type Task ¶
type Task struct {
Name string
Schedule string // cron expression
Timeout time.Duration // per-task timeout (0 = defaultTaskTimeout)
Disabled bool // if true, task is off by default (can be enabled via override)
Fn func(ctx context.Context) error
}
Task is a periodic task definition.
func DefaultTasks ¶
func DefaultTasks() []Task
DefaultTasks returns the standard set of periodic tasks. Each task's Fn should be set by the caller with access to services.
type TaskOverride ¶ added in v0.0.10
type TaskOverride struct {
TaskName string `json:"task_name"`
Enabled bool `json:"enabled"`
CustomSchedule string `json:"custom_schedule"` // empty = use default
UpdatedAt int64 `json:"updated_at"`
}
TaskOverride holds per-task configuration from the database.
type TaskStatus ¶ added in v0.0.10
type TaskStatus struct {
Name string `json:"name"`
DefaultSchedule string `json:"default_schedule"`
EffectiveSchedule string `json:"effective_schedule"`
Enabled bool `json:"enabled"`
DefaultDisabled bool `json:"default_disabled"`
IsOverridden bool `json:"is_overridden"`
Timeout string `json:"timeout"`
LastRun *ExecutionRecord `json:"last_run,omitempty"`
}
TaskStatus is the runtime status of a task (for the API).