summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-11-17 00:57:50 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-11-17 20:22:57 +0800
commit6d1c5761cd520f3cb7fa4dbb1a1937c29f468884 (patch)
treed5edc1d78a744d62bbe6832b10a022ac12fc63a6 /app
parent891465ba8cd57bb928e82ba070f2d7efb63f6282 (diff)
downloadgitlab-ce-6d1c5761cd520f3cb7fa4dbb1a1937c29f468884.tar.gz
Improve how we could cancel pipelines:
* Introduce `HasStatus.cancelable` which we might be able to cancel * Cancel and check upon `cancelable` * Also cancel on `CommitStatus` rather than just `Ci::Build` Fixes #23635 Fixes #17845
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/models/concerns/has_status.rb4
2 files changed, 6 insertions, 2 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 3fee6c18770..4eb85f62ee4 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -167,11 +167,11 @@ module Ci
end
def cancelable?
- builds.running_or_pending.any?
+ statuses.cancelable.any?
end
def cancel_running
- builds.running_or_pending.each(&:cancel)
+ statuses.cancelable.each(&:cancel)
end
def retry_failed(user)
diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb
index ef3e73a4072..1332743429d 100644
--- a/app/models/concerns/has_status.rb
+++ b/app/models/concerns/has_status.rb
@@ -73,6 +73,10 @@ module HasStatus
scope :skipped, -> { where(status: 'skipped') }
scope :running_or_pending, -> { where(status: [:running, :pending]) }
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
+
+ scope :cancelable, -> do
+ where(status: [:running, :pending, :created])
+ end
end
def started?