cron

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 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 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) 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) 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) UnregisterTask

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

UnregisterTask removes a task from the running cron.

Jump to

Keyboard shortcuts

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