diff options
| author | Shinya Maeda <shinya@gitlab.com> | 2019-06-19 19:12:48 +0700 |
|---|---|---|
| committer | Shinya Maeda <shinya@gitlab.com> | 2019-06-24 14:53:36 +0700 |
| commit | a22e68bf46e660aa21bf2ae0073a51b9a950f870 (patch) | |
| tree | 9c5fd271bdffae9583279ec4a7d93ed7af42cd06 /app | |
| parent | 97e8f494427582251af55056d25459bf038dabbc (diff) | |
| download | gitlab-ce-a22e68bf46e660aa21bf2ae0073a51b9a950f870.tar.gz | |
Fix pipeline schedule edge casefix-pipeline-schedule-edge-case
If pipeline schedule is to run at the exact same time with when cron
worker runs, the pipeline schedule will not be executed at the
ideal timing.
We fix this bug by comparing the exact matching of ideal and
cron worker's next run at.
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/ci/pipeline_schedule.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/models/ci/pipeline_schedule.rb b/app/models/ci/pipeline_schedule.rb index 6a4241c94bc..ba8cea0cea9 100644 --- a/app/models/ci/pipeline_schedule.rb +++ b/app/models/ci/pipeline_schedule.rb @@ -55,15 +55,20 @@ module Ci # This way, a schedule like `*/1 * * * *` won't be triggered in a short interval # when PipelineScheduleWorker runs irregularly by Sidekiq Memory Killer. def set_next_run_at - self.next_run_at = Gitlab::Ci::CronParser.new(Settings.cron_jobs['pipeline_schedule_worker']['cron'], - Time.zone.name) - .next_time_from(ideal_next_run_at) + now = Time.zone.now + ideal_next_run = ideal_next_run_from(now) + + self.next_run_at = if ideal_next_run == cron_worker_next_run_from(now) + ideal_next_run + else + cron_worker_next_run_from(ideal_next_run) + end end def schedule_next_run! save! # with set_next_run_at rescue ActiveRecord::RecordInvalid - update_attribute(:next_run_at, nil) # update without validation + update_column(:next_run_at, nil) # update without validation end def job_variables @@ -72,9 +77,15 @@ module Ci private - def ideal_next_run_at + def ideal_next_run_from(start_time) Gitlab::Ci::CronParser.new(cron, cron_timezone) - .next_time_from(Time.zone.now) + .next_time_from(start_time) + end + + def cron_worker_next_run_from(start_time) + Gitlab::Ci::CronParser.new(Settings.cron_jobs['pipeline_schedule_worker']['cron'], + Time.zone.name) + .next_time_from(start_time) end end end |
