diff options
Diffstat (limited to 'app/services/deployments/older_deployments_drop_service.rb')
-rw-r--r-- | app/services/deployments/older_deployments_drop_service.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/services/deployments/older_deployments_drop_service.rb b/app/services/deployments/older_deployments_drop_service.rb new file mode 100644 index 00000000000..122f8ac89ed --- /dev/null +++ b/app/services/deployments/older_deployments_drop_service.rb @@ -0,0 +1,31 @@ +# 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| + older_deployment.deployable&.drop!(:forward_deployment_failure) + rescue => e + 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 |