Welcome to mirror list, hosted at ThFree Co, Russian Federation.

older_deployments_drop_service.rb « deployments « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15384fb0db1e15b08d381e1c4a6994bc424c2775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_builds.each do |build|
        next if build.manual?

        Gitlab::OptimisticLocking.retry_lock(build, name: 'older_deployments_drop') do |build|
          build.drop(:forward_deployment_failure)
        end
      rescue StandardError => e
        Gitlab::ErrorTracking.track_exception(e, subject_id: @deployment.id, build_id: build.id)
      end
    end

    private

    def older_deployments_builds
      @deployment
        .environment
        .active_deployments
        .older_than(@deployment)
        .builds
    end
  end
end