Commit b1dc850a authored by Rydkin Maxim's avatar Rydkin Maxim

move `auto_cancelable_pipelines` method to `create_pipeline_service.rb`

parent c77b1cb0
...@@ -127,14 +127,6 @@ module Ci ...@@ -127,14 +127,6 @@ module Ci
where.not(duration: nil).sum(:duration) where.not(duration: nil).sum(:duration)
end end
def auto_cancelable_pipelines
project.pipelines
.where(ref: ref)
.where.not(id: id)
.where.not(sha: project.repository.sha_from_ref(ref))
.created_or_pending
end
def stage(name) def stage(name)
stage = Ci::Stage.new(self, name: name) stage = Ci::Stage.new(self, name: name)
stage unless stage.statuses_count.zero? stage unless stage.statuses_count.zero?
......
...@@ -66,8 +66,7 @@ module Ci ...@@ -66,8 +66,7 @@ module Ci
end end
def cancel_pending_pipelines def cancel_pending_pipelines
Gitlab::OptimisticLocking.retry_lock( Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables|
pipeline.auto_cancelable_pipelines) do |cancelables|
cancelables.find_each do |cancelable| cancelables.find_each do |cancelable|
cancelable.cancel_running cancelable.cancel_running
cancelable.update_attributes(auto_canceled_by: pipeline.id) cancelable.update_attributes(auto_canceled_by: pipeline.id)
...@@ -75,6 +74,14 @@ module Ci ...@@ -75,6 +74,14 @@ module Ci
end end
end end
def auto_cancelable_pipelines
project.pipelines
.where(ref: pipeline.ref)
.where.not(id: pipeline.id)
.where.not(sha: project.repository.sha_from_ref(pipeline.ref))
.created_or_pending
end
def commit def commit
@commit ||= project.commit(origin_sha || origin_ref) @commit ||= project.commit(origin_sha || origin_ref)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment