debian-mirror-gitlab/app/services/deployments/older_deployments_drop_service.rb

36 lines
837 B
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# 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?
2021-11-18 22:05:49 +05:30
older_deployments_builds.each do |build|
2022-01-26 12:08:38 +05:30
next if build.manual?
2021-11-18 22:05:49 +05:30
Gitlab::OptimisticLocking.retry_lock(build, name: 'older_deployments_drop') do |build|
build.drop(:forward_deployment_failure)
2020-05-24 23:13:21 +05:30
end
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-11-18 22:05:49 +05:30
Gitlab::ErrorTracking.track_exception(e, subject_id: @deployment.id, build_id: build.id)
2020-03-13 15:44:24 +05:30
end
end
private
2021-11-18 22:05:49 +05:30
def older_deployments_builds
2020-03-13 15:44:24 +05:30
@deployment
.environment
.active_deployments
.older_than(@deployment)
2021-11-18 22:05:49 +05:30
.builds
2020-03-13 15:44:24 +05:30
end
end
end