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 ¶
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 ¶
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 ¶
RunningJobCount returns the number of currently executing jobs