cron

package
v1.10.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateSpec

func ValidateSpec(spec string) error

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 (*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

func (m *Manager) RegisterTask(kind string, id uint, name, schedule string, fn func() error) error

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

func (m *Manager) SetLeader(l Leader)

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 (m *Manager) SetRecoveryPointGate(fn func() error)

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

func (m *Manager) Snapshot() []JobStatus

Snapshot returns the current status of every registered task.

func (*Manager) Start

func (m *Manager) Start()

Start loads all enabled schedules and begins the cron loop.

func (*Manager) Stop

func (m *Manager) Stop()

Stop halts the cron loop.

func (*Manager) Unregister

func (m *Manager) Unregister(scheduleID uint)

Unregister removes a backup schedule from the running cron.

func (*Manager) UnregisterSet added in v1.9.6

func (m *Manager) UnregisterSet(scheduleID uint)

UnregisterSet removes a recovery-point schedule from the running cron.

func (*Manager) UnregisterTask

func (m *Manager) UnregisterTask(kind string, id uint)

UnregisterTask removes a task from the running cron.

func (*Manager) UnregisterVolumeBackup added in v1.10.7

func (m *Manager) UnregisterVolumeBackup(scheduleID uint)

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.

Jump to

Keyboard shortcuts

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