scheduler

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultScheduleFor added in v0.0.10

func DefaultScheduleFor(name string) string

DefaultScheduleFor returns the default schedule for a task name, or empty string.

func DefaultTimeoutFor added in v0.0.10

func DefaultTimeoutFor(name string) time.Duration

DefaultTimeoutFor returns the default timeout for a task name.

func KnownTaskNames added in v0.0.10

func KnownTaskNames() map[string]bool

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 New

func New() *Scheduler

New creates a new Scheduler.

func (*Scheduler) AddOrUpdateTask added in v0.0.10

func (s *Scheduler) AddOrUpdateTask(task Task) error

AddOrUpdateTask removes an existing cron entry (if any) and adds a new one.

func (*Scheduler) GetDefaults added in v0.0.10

func (s *Scheduler) GetDefaults() []Task

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

func (s *Scheduler) RemoveTask(name string)

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.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully stops the scheduler and cancels running task contexts.

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).

Jump to

Keyboard shortcuts

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