Documentation
¶
Overview ¶
Package cron is a generic recurring-task scheduler over robfig/cron. Tasks are keyed by a string ("backup:12", "cronjob:34") so different sources share one loop and one status view without id collisions. Schedules load at startup and can be (de)registered at runtime.
Index ¶
- func ValidateSpec(spec string) error
- type JobStatus
- type Manager
- func (m *Manager) Register(s models.BackupSchedule)
- func (m *Manager) RegisterTask(kind string, id uint, name, schedule string, fn func() error) error
- func (m *Manager) Snapshot() []JobStatus
- func (m *Manager) Start()
- func (m *Manager) Stop()
- func (m *Manager) Unregister(scheduleID uint)
- func (m *Manager) UnregisterTask(kind string, id uint)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateSpec ¶
ValidateSpec reports whether spec is a valid standard (5-field) cron expression, so callers can reject a bad schedule before persisting it.
Types ¶
type JobStatus ¶
type JobStatus struct {
Kind string `json:"kind"` // backup | cronjob
ID uint `json:"id"` // source-specific id (schedule / cronjob)
Name string `json:"name"`
Schedule string `json:"schedule"`
Running bool `json:"running"`
LastRunAt *time.Time `json:"last_run_at"`
LastError string `json:"last_error,omitempty"`
NextRunAt *time.Time `json:"next_run_at"`
}
JobStatus is a point-in-time snapshot of a scheduled task for the admin UI.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager(backups *backup.Service, dbs *repositories.DatabaseRepository, sched *repositories.BackupRepository, settings *backupsettings.Service) *Manager
func (*Manager) Register ¶
func (m *Manager) Register(s models.BackupSchedule)
Register adds (or replaces) a backup schedule in the running cron.
func (*Manager) RegisterTask ¶
RegisterTask adds (or replaces) a task in the running cron, keyed by kind:id. fn runs on each tick; its error is surfaced in the snapshot's LastError.
func (*Manager) Start ¶
func (m *Manager) Start()
Start loads all enabled schedules and begins the cron loop.
func (*Manager) Unregister ¶
Unregister removes a backup schedule from the running cron.
func (*Manager) UnregisterTask ¶
UnregisterTask removes a task from the running cron.