debian-mirror-gitlab/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines.rb
2020-10-24 23:57:45 +05:30

40 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Chain
class CancelPendingPipelines < Chain::Base
include Chain::Helpers
def perform!
return unless project.auto_cancel_pending_pipelines?
Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables|
cancelables.find_each do |cancelable|
cancelable.auto_cancel_running(pipeline)
end
end
end
def break?
false
end
private
# rubocop: disable CodeReuse/ActiveRecord
def auto_cancelable_pipelines
project.ci_pipelines
.where(ref: pipeline.ref)
.where.not(id: pipeline.same_family_pipeline_ids)
.where.not(sha: project.commit(pipeline.ref).try(:id))
.alive_or_scheduled
.with_only_interruptible_builds
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
end