2020-02-17 04:08:52 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Deployments
|
|
|
|
class OlderDeploymentsDropService
|
|
|
|
attr_reader :deployment
|
|
|
|
|
|
|
|
def initialize(deployment_id)
|
|
|
|
@deployment = Deployment.find_by_id(deployment_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return unless @deployment&.running?
|
|
|
|
|
|
|
|
older_deployments.find_each do |older_deployment|
|
2021-03-02 10:10:57 -05:00
|
|
|
Gitlab::OptimisticLocking.retry_lock(older_deployment.deployable, name: 'older_deployments_drop') do |deployable|
|
2020-05-18 14:08:22 -04:00
|
|
|
deployable.drop(:forward_deployment_failure)
|
|
|
|
end
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2020-02-17 04:08:52 -05:00
|
|
|
Gitlab::ErrorTracking.track_exception(e, subject_id: @deployment.id, deployment_id: older_deployment.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def older_deployments
|
|
|
|
@deployment
|
|
|
|
.environment
|
|
|
|
.active_deployments
|
|
|
|
.older_than(@deployment)
|
|
|
|
.with_deployable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|