scheduler

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateTimezone added in v1.1.0

func ValidateTimezone(name string) (string, error)

ValidateTimezone validates a non-empty IANA timezone identifier and returns its trimmed canonical input value.

Types

type JobCallback

type JobCallback func(ctx context.Context, jobName string) error

JobCallback is invoked by scheduler ticks.

type JobSchedule

type JobSchedule struct {
	JobName   string    `json:"job_name"`
	Enabled   bool      `json:"enabled"`
	CronSpec  string    `json:"cron_spec"`
	NextRun   time.Time `json:"next_run,omitempty"`
	LastError string    `json:"last_error,omitempty"`
}

JobSchedule is one persisted scheduler configuration with runtime next-run state.

type Service

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

Service loads, validates, and executes cron schedules backed by settings.

func New

func New(store SettingsStore, logger *slog.Logger) (*Service, error)

func (*Service) ListSchedules

func (s *Service) ListSchedules(ctx context.Context) ([]JobSchedule, error)

ListSchedules returns persisted schedule configuration plus runtime next-run values.

func (*Service) LoadFromSettings

func (s *Service) LoadFromSettings(ctx context.Context) error

LoadFromSettings rebuilds entries using persisted settings.

func (*Service) NextRun

func (s *Service) NextRun(jobName string) (time.Time, bool)

NextRun returns the next run time for a job when enabled.

func (*Service) RegisterJob

func (s *Service) RegisterJob(jobName string, callback JobCallback) error

RegisterJob registers a runtime callback for a supported job name.

func (*Service) Start

func (s *Service) Start()

Start begins cron execution for currently loaded entries.

func (*Service) Stop

func (s *Service) Stop() context.Context

Stop halts scheduler execution.

func (*Service) Timezone

func (s *Service) Timezone() string

Timezone returns the active scheduler timezone name.

func (*Service) UpdateJobSchedule

func (s *Service) UpdateJobSchedule(ctx context.Context, jobName string, enabled bool, cronSpec string) error

UpdateJobSchedule validates, persists, and applies one job schedule at runtime.

func (*Service) UpdateTimezone

func (s *Service) UpdateTimezone(ctx context.Context, timezone string) error

UpdateTimezone persists timezone and reloads schedule entries.

func (*Service) ValidateCron

func (s *Service) ValidateCron(spec string) error

ValidateCron validates cron spec with support for 5-field and optional-seconds format.

type SettingsStore

type SettingsStore interface {
	GetSetting(ctx context.Context, key string) (string, error)
	SetSettings(ctx context.Context, values map[string]string) error
}

SettingsStore reads and writes automation settings.

Jump to

Keyboard shortcuts

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