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

archive_in_project_service.rb « deployments « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a593721f3903c5fba3c7b502f187569f43f5abeb (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
# frozen_string_literal: true

module Deployments
  # This service archives old deploymets and deletes deployment refs for
  # keeping the project repository performant.
  class ArchiveInProjectService < ::BaseService
    BATCH_SIZE = 100

    def execute
      unless ::Feature.enabled?(:deployments_archive, project, default_enabled: :yaml)
        return error('Feature flag is not enabled')
      end

      deployments = Deployment.archivables_in(project, limit: BATCH_SIZE)

      return success(result: :empty) if deployments.empty?

      ids = deployments.map(&:id)
      ref_paths = deployments.map(&:ref_path)

      project.repository.delete_refs(*ref_paths)
      project.deployments.id_in(ids).update_all(archived: true)

      success(result: :archived, count: ids.count)
    end
  end
end