diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-04-06 21:32:56 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-04-06 21:32:56 +0800 |
commit | 057c0d7a5c062f3030bcc46614ef2442009002de (patch) | |
tree | e4e9f8b092500950e914955f8d257c3b443a77dd /app | |
parent | 98a4aca6b5ce503543b0e325212265a365e64d75 (diff) | |
download | gitlab-ce-057c0d7a5c062f3030bcc46614ef2442009002de.tar.gz |
Also track auto-cancelling in jobs, detail:
Not only tracking auto-cancelling in pipelines,
we'll also track this in jobs because pipelines
could be retried and the information would get lost
when this happened. Also erase auto-cancelling
relation for pipelines when they're retried.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/pipeline.rb | 19 | ||||
-rw-r--r-- | app/models/commit_status.rb | 5 | ||||
-rw-r--r-- | app/presenters/ci/build_presenter.rb | 4 | ||||
-rw-r--r-- | app/presenters/ci/pipeline_presenter.rb | 4 | ||||
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 3 |
5 files changed, 29 insertions, 6 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 8aad149519e..e03def25755 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -11,6 +11,8 @@ module Ci belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' + has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' + has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id @@ -93,6 +95,10 @@ module Ci PipelineNotificationWorker.perform_async(pipeline.id) end end + + after_transition :canceled => any - [:canceled] do |pipeline| + pipeline.update(auto_canceled_by: nil) + end end # ref can't be HEAD or SHA, can only be branch/tag name @@ -226,10 +232,21 @@ module Ci def cancel_running Gitlab::OptimisticLocking.retry_lock( statuses.cancelable) do |cancelable| - cancelable.find_each(&:cancel) + cancelable.find_each do |job| + yield(job) if block_given? + job.cancel + end end end + def auto_cancel_running(pipeline) + update(auto_canceled_by: pipeline) + + cancel_running do |job| + job.auto_canceled_by = pipeline + end + end + def retry_failed(current_user) Ci::RetryPipelineService.new(project, current_user) .execute(self) diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 17b322b5ae3..2c4033146bf 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -7,6 +7,7 @@ class CommitStatus < ActiveRecord::Base belongs_to :project belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id + belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' belongs_to :user delegate :commit, to: :pipeline @@ -137,6 +138,10 @@ class CommitStatus < ActiveRecord::Base false end + def auto_canceled? + canceled? && auto_canceled_by_id? + end + # Added in 9.0 to keep backward compatibility for projects exported in 8.17 # and prior. def gl_project_id diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index d9970396cc6..c495c3f39bb 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -13,8 +13,8 @@ module Ci end def status_title - if canceled? && pipeline.auto_canceled? - "Job is redundant and is auto-canceled by Pipeline ##{pipeline.auto_canceled_by_id}" + if auto_canceled? + "Job is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" end end end diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb index b8e74bf5509..a542bdd8295 100644 --- a/app/presenters/ci/pipeline_presenter.rb +++ b/app/presenters/ci/pipeline_presenter.rb @@ -3,7 +3,9 @@ module Ci presents :pipeline def status_title - "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? + if auto_canceled? + "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" + end end end end diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index f944c869922..21350be5557 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -68,8 +68,7 @@ module Ci def cancel_pending_pipelines Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables| cancelables.find_each do |cancelable| - cancelable.cancel_running - cancelable.update_attributes(auto_canceled_by_id: pipeline.id) + cancelable.auto_cancel_running(pipeline) end end end |