summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-06-04 08:22:14 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2019-06-04 08:22:14 +0000
commit554fbb2a49936a8038ee2e26231b69922009023a (patch)
treeb27f26e64b5947364a027e3c87aabd1acb345c22 /app/models
parentd16c11ab36d91fc51a01406fa77ee2bf307ad8f5 (diff)
parent6a18a411a30e9e7406ba9335ab502ec396add662 (diff)
downloadgitlab-ce-554fbb2a49936a8038ee2e26231b69922009023a.tar.gz
Merge branch 'set-real-next-run-at-for-preventing-duplciate-pipeline-creations' into 'master'
Make pipeline schedule worker resilient Closes gitlab-com/gl-infra/production#805 and #61955 See merge request gitlab-org/gitlab-ce!28407
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/pipeline_schedule.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/app/models/ci/pipeline_schedule.rb b/app/models/ci/pipeline_schedule.rb
index c0a0ca9acf6..c40ad39be61 100644
--- a/app/models/ci/pipeline_schedule.rb
+++ b/app/models/ci/pipeline_schedule.rb
@@ -27,9 +27,13 @@ module Ci
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
+ scope :runnable_schedules, -> { active.where("next_run_at < ?", Time.now) }
+ scope :preloaded, -> { preload(:owner, :project) }
accepts_nested_attributes_for :variables, allow_destroy: true
+ alias_attribute :real_next_run, :next_run_at
+
def owned_by?(current_user)
owner == current_user
end
@@ -46,8 +50,14 @@ module Ci
update_attribute(:active, false)
end
+ ##
+ # The `next_run_at` column is set to the actual execution date of `PipelineScheduleWorker`.
+ # 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(cron, cron_timezone).next_time_from(Time.now)
+ 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)
end
def schedule_next_run!
@@ -56,15 +66,14 @@ module Ci
update_attribute(:next_run_at, nil) # update without validation
end
- def real_next_run(
- worker_cron: Settings.cron_jobs['pipeline_schedule_worker']['cron'],
- worker_time_zone: Time.zone.name)
- Gitlab::Ci::CronParser.new(worker_cron, worker_time_zone)
- .next_time_from(next_run_at)
- end
-
def job_variables
variables&.map(&:to_runner_variable) || []
end
+
+ private
+
+ def ideal_next_run_at
+ Gitlab::Ci::CronParser.new(cron, cron_timezone).next_time_from(Time.now)
+ end
end
end