Documentation
¶
Index ¶
- Constants
- Variables
- func Entries() []cron.Entry
- func Every(duration time.Duration, job cron.Job)
- func In(duration time.Duration, job cron.Job)
- func Now(job cron.Job)
- func Remove(id cron.EntryID)
- func RemoveJobByName(jobName string) error
- func Schedule(spec string, job cron.Job) error
- func Start(options ...int)
- func StatusJson() map[string]interface{}
- func Stop()
- func UpdateJobIntervalByName(jobName string, newInterval time.Duration) error
- func UpdateJobScheduleByName(jobName, newSpec string) error
- type Func
- type Job
- type StatusData
Constants ¶
const ( UNNAMED_JOB = "(unnamed)" // Default name for unnamed jobs JOB_RUNNING_STATUS = "RUNNING" // Job status constants JOB_IDLE_STATUS = "IDLE" // Job status constants )
const DEFAULT_JOB_POOL_SIZE = 10 // Default number of concurrent jobs
Variables ¶
var ( MainCron *cron.Cron // Job scheduler singleton instance HideBanner bool = false // Flag to control banner display )
Functions ¶
func Now ¶
Now runs the given job once, immediately.
It pre-stamps lastRun synchronously before launching the goroutine so that any StatusPage call immediately after Now() returns sees the updated Prev — important for nudge-based WebSocket pushes. The goroutine's Run() will overwrite lastRun ~1ms later with the actual start time; both writes are atomic and the delta is negligible.
It reuses the registered *Job instance when possible so that Status and Latency updates during the run are visible in StatusPage.
func RemoveJobByName ¶
RemoveJobByName removes a scheduled job by its name.
func StatusJson ¶
func StatusJson() map[string]interface{}
StatusJson returns the job status as a JSON-serialisable map.
func UpdateJobIntervalByName ¶
UpdateJobIntervalByName updates an existing job's execution interval by its name.
func UpdateJobScheduleByName ¶
UpdateJobScheduleByName updates an existing job's schedule by its name.
Types ¶
type Job ¶
type Job struct {
Name string `json:"name"`
Status string `json:"status"`
Latency string `json:"latency"`
// contains filtered or unexported fields
}
Job represents a scheduled task within the JobRunner system. It wraps an inner cron.Job and maintains execution metadata such as name, status, latency, last-run time, and total run count.
lastRun and runCount are placed first in the struct to guarantee 64-bit atomic alignment on 32-bit platforms (Go spec requirement).
func (*Job) LastRun ¶ added in v1.0.2
LastRun returns the time this job last began executing (scheduled or manual). Returns the zero time if the job has never run.
func (*Job) Run ¶
func (j *Job) Run()
Run executes the job and updates the job status, latency, last-run time, and run count.
func (*Job) RunCount ¶ added in v1.0.2
RunCount returns the total number of times this job has started executing.
func (*Job) StatusUpdate ¶
StatusUpdate updates the job status based on the atomic status flag
type StatusData ¶
type StatusData struct {
Id cron.EntryID `json:"id"`
JobRunner *Job `json:"jobRunner"`
Next time.Time `json:"next"`
Prev time.Time `json:"prev"`
RunCount int64 `json:"runCount"`
}
StatusData holds the observable state of a single scheduled job entry. Prev reflects the last execution start time across all execution paths (scheduled and manual), sourced from the Job's own atomic lastRun field.
func StatusPage ¶
func StatusPage() []StatusData
StatusPage returns the current state of all registered jobs. Prev is taken from the Job's own lastRun field — the single source of truth for execution time regardless of whether the run was scheduled or manual.
JobRunner