2020-10-24 23:57:45 +05:30
|
|
|
# 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?
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines, name: 'cancel_pending_pipelines') do |cancelables|
|
2020-10-24 23:57:45 +05:30
|
|
|
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
|
2021-03-11 19:13:27 +05:30
|
|
|
project.all_pipelines.ci_and_parent_sources
|
2020-10-24 23:57:45 +05:30
|
|
|
.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
|