cron

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Name      string
	Spec      string
	Cmd       func()
	CheckFunc func() bool // Function to check if job should be enabled
	EntryID   cron.EntryID
	Running   bool
	// contains filtered or unexported fields
}

Job definition for the manager

type Manager

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

Manager manages cron jobs with support for dynamic reloading and distributed locking

func NewManager

func NewManager(rdb *redis.Client) *Manager

NewManager creates a new Cron Manager rdb is optional. If provided, distributed locking via Redis will be attempted (implementation dependent on wrapper). Actually, here we implement simple local locking or we can extend for Redis distribution if needed. The original implementation used atomic CAS for local locking and didn't seem to use Redis for distributed locking explicitly in the wrapper shown? Wait, checking original code: func (s *CronService) wrapper(job *Job) func() { ... if !atomic.CompareAndSwapUint32(&job.executing, 0, 1) ... This is local concurrency control (prevent overlapping runs of same job instance). The original code passed `rdb` but seemingly didn't use it in `wrapper` for distributed lock (maybe I missed it or it was for future use). Let's keep `rdb` in struct for potential use or if we want to add distributed lock later.

func (*Manager) Refresh

func (m *Manager) Refresh()

Refresh checks all jobs and enables/disables them based on CheckFunc

func (*Manager) Register

func (m *Manager) Register(name, spec string, cmd func(), checkFunc func() bool)

Register adds a job to the manager. It DOES NOT schedule it immediately; scheduling happens in Refresh loop or if we call Refresh manually. checkFunc: returns true if job should be enabled.

func (*Manager) RunningJobCount

func (m *Manager) RunningJobCount() int

RunningJobCount returns the number of currently executing jobs

func (*Manager) Start

func (m *Manager) Start()

Start begins the cron service and the dynamic watcher

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the cron service

Jump to

Keyboard shortcuts

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