From 2155872458851e9d04d6ffdca73d0935ff8fff54 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 21 Oct 2024 21:08:34 +0545 Subject: [PATCH] make the start of cron runner behavior configurable --- job/job.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/job/job.go b/job/job.go index 6a29abae..3267de83 100644 --- a/job/job.go +++ b/job/job.go @@ -42,8 +42,19 @@ const ( var ( EvictedJobs chan uuid.UUID startedJobHistory = false + + // startCronOnSchedule dictates whether to start the cron runner + // when a job is scheduled to it. + startCronOnSchedule = true ) +// DisableCronStartOnSchedule disables the default bahevior of +// starting the cron runner when a job is scheduled via +// `.AddToSchduler()` +func DisableCronStartOnSchedule() { + startCronOnSchedule = false +} + func StartJobHistoryEvictor(ctx context.Context) { if !startedJobHistory { if EvictedJobs == nil { @@ -563,6 +574,9 @@ func (j *Job) GetResourcedName() string { func (j *Job) AddToScheduler(cronRunner *cron.Cron) error { echo.RegisterCron(cronRunner) + if startCronOnSchedule { + cronRunner.Start() + } schedule := j.Schedule if override, ok := j.GetProperty("schedule"); ok {