Skip to main content

GoCronScheduler

This class manages a set of cron jobs, with one job per active trigger. It is designed to be safe for concurrent use.

Methods


Start()

@classmethod
def Start()

Starts the cron scheduler, allowing jobs to begin executing according to their schedules. This method should be called to activate the scheduling mechanism.


Stop()

@classmethod
def Stop() - > context.Context

Stops the cron scheduler, preventing any further job executions. Callers should use the returned context to wait for all running jobs to complete gracefully.

Returns

TypeDescription
context.ContextA context that will be canceled once all running jobs have finished.

UpdateSchedules()

@classmethod
def UpdateSchedules(
ctx: context.Context,
triggers: []*models.Trigger
)

Updates the set of scheduled cron jobs based on the provided triggers. This method adds new jobs, removes jobs for deleted triggers, and updates existing jobs whose schedules have changed.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the update operation, allowing for cancellation or timeouts.
triggers[]*models.TriggerA slice of trigger models representing the desired state of scheduled jobs. Each trigger defines a cron schedule and the job to execute.

CatchupAll()

@classmethod
def CatchupAll(
ctx: context.Context,
triggers: []*models.Trigger,
now: time.Time,
maxRunsPerLoop: int
)

Executes any jobs that should have run between their last scheduled time and the provided 'now' timestamp, up to a maximum number of runs per loop. This is useful for ensuring jobs are run even if the scheduler was temporarily down.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the catch-up operation, allowing for cancellation or timeouts.
triggers[]*models.TriggerA slice of trigger models for which catch-up runs should be considered. Each trigger defines a cron schedule.
nowtime.TimeThe current time against which to evaluate missed job runs. Jobs scheduled before this time but after their last run will be considered for catch-up.
maxRunsPerLoopintThe maximum number of catch-up runs to execute in a single iteration. This prevents overwhelming the system with too many jobs at once.