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
| Type | Description |
|---|---|
context.Context | A context that will be canceled once all running jobs have finished their execution. |
UpdateSchedules()
@classmethod
def UpdateSchedules(
ctx: context.Context,
triggers: []*models.Trigger
)
Updates the set of scheduled jobs based on the provided triggers, adding new jobs, updating existing ones, or removing those no longer present. This method ensures the scheduler's jobs reflect the current desired state.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, used for cancellation or timeouts. |
| triggers | []*models.Trigger | A slice of trigger models representing the desired state of all scheduled jobs. |
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 method is used to ensure jobs are not missed if the scheduler was down or delayed.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, used for cancellation or timeouts. |
| triggers | []*models.Trigger | A slice of trigger models for which catch-up runs should be considered. |
| now | time.Time | The current time against which to evaluate missed job schedules. |
| maxRunsPerLoop | int | The maximum number of catch-up runs to execute in a single loop iteration to prevent overwhelming the system. |