Skip to content

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:

  1. PipelineScheduleWorker picks up a schedule because next_run_at < Time.zone.now
  2. RunPipelineScheduleWorker is enqueued with scheduling: true
  3. Before the worker executes, an external update (e.g., via API) triggers the before_save hook, updating next_run_at to a future time
  4. 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? or cron_timezone_changed?, this even handles cases where the exact same value comes in.
  • Override schedule_next_run to explicitly call set_next_run_at and then saving. I also added a guard to assert that this method doesn't run if cron or cron_timezone also change since it will recalculate next_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

Merge request reports

Loading