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 Leader
- type Manager
- func (m *Manager) Register(s models.BackupSchedule)
- func (m *Manager) RegisterLocalTask(kind string, id uint, name, schedule string, fn func() error) error
- func (m *Manager) RegisterSet(s models.DatabaseBackupSetSchedule)
- func (m *Manager) RegisterTask(kind string, id uint, name, schedule string, fn func() error) error
- func (m *Manager) RegisterVolumeBackup(s models.VolumeBackupSchedule)
- func (m *Manager) SetLeader(l Leader)
- func (m *Manager) SetRecoveryPointGate(fn func() error)
- func (m *Manager) SetVolumeBackups(v VolumeScheduler)
- func (m *Manager) Snapshot() []JobStatus
- func (m *Manager) Start()
- func (m *Manager) Stop()
- func (m *Manager) Unregister(scheduleID uint)
- func (m *Manager) UnregisterSet(scheduleID uint)
- func (m *Manager) UnregisterTask(kind string, id uint)
- func (m *Manager) UnregisterVolumeBackup(scheduleID uint)
- type VolumeScheduler
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 Leader ¶ added in v1.10.1
type Leader interface {
Leading() bool
}
Leader reports whether this process leads the control plane. Satisfied by *leader.Elector.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager(backups *backup.Service, dbs *repositories.DatabaseRepository, sched *repositories.BackupRepository, sets *repositories.DatabaseBackupSetRepository, 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) RegisterLocalTask ¶ added in v1.10.1
func (m *Manager) RegisterLocalTask(kind string, id uint, name, schedule string, fn func() error) error
RegisterLocalTask is RegisterTask for a task that only touches this process's own state, such as the agent tunnels it holds, so it runs whether or not the process leads.
func (*Manager) RegisterSet ¶ added in v1.9.6
func (m *Manager) RegisterSet(s models.DatabaseBackupSetSchedule)
RegisterSet adds (or replaces) an instance-level recovery-point schedule.
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) RegisterVolumeBackup ¶ added in v1.10.7
func (m *Manager) RegisterVolumeBackup(s models.VolumeBackupSchedule)
RegisterVolumeBackup adds (or replaces) a volume recovery-point schedule.
func (*Manager) SetLeader ¶ added in v1.10.1
SetLeader runs tasks only while l leads, so two control-plane processes never run the same job twice. Tasks registered with RegisterLocalTask run regardless. Without a leader every task runs.
func (*Manager) SetRecoveryPointGate ¶ added in v1.10.3
func (*Manager) SetVolumeBackups ¶ added in v1.10.7
func (m *Manager) SetVolumeBackups(v VolumeScheduler)
SetVolumeBackups wires volume recovery-point schedules and registers every enabled one. It is a setter rather than a NewManager argument because the volume service is built after the manager; the scheduler is already running by then, which robfig/cron allows.
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) UnregisterSet ¶ added in v1.9.6
UnregisterSet removes a recovery-point schedule from the running cron.
func (*Manager) UnregisterTask ¶
UnregisterTask removes a task from the running cron.
func (*Manager) UnregisterVolumeBackup ¶ added in v1.10.7
UnregisterVolumeBackup removes a volume recovery-point schedule from the running cron.
type VolumeScheduler ¶ added in v1.10.7
type VolumeScheduler interface {
ListEnabledSchedules() ([]models.VolumeBackupSchedule, error)
RunSchedule(ctx context.Context, workspaceID, scheduleID uint) error
}
VolumeScheduler runs volume recovery-point schedules. Satisfied by *volumebackup.Service.