Remove redundant validation
What does this MR do and why?
This MR fixes a race condition that prevents scheduled pipeline execution when a pipeline schedule is updated during worker processing.
Race Condition
The race condition occurs when:
-
PipelineScheduleWorker
picks up a schedule becausenext_run_at < Time.zone.now
-
RunPipelineScheduleWorker
is enqueued withscheduling: true
- Before the worker executes, an external update (e.g., via API) triggers the
before_save
hook, updatingnext_run_at
to a future time - When
RunPipelineScheduleWorker
executes,next_run_at
has been set to the future, so the validation fails, even though the worker was scheduled based on the initial date.
Solution
- Modified the before save hook to conditionally execute only if
cron_changed?
orcron_timezone_changed?
, this even handles cases where the exact same value comes in. - Override
schedule_next_run
to explicitly callset_next_run_at
and then saving. I also added a guard to assert that this method doesn't run ifcron
orcron_timezone
also change since it will recalculatenext_run_at
from the hook too, practically only allowing this method to calculate next_run_at for the current cron.
Closes #567690
Edited by Panos Kanellidis