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

schedule_bulk_repository_shard_moves_service.rb « projects « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd49910207f1e99a5f8d851e331cdc6df54b07ea (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 Projects
  # Tries to schedule a move for every project with repositories on the source shard
  class ScheduleBulkRepositoryShardMovesService
    include BaseServiceUtility

    def execute(source_storage_name, destination_storage_name = nil)
      shard = Shard.find_by_name!(source_storage_name)

      ProjectRepository.for_shard(shard).each_batch(column: :project_id) do |relation|
        Project.id_in(relation.select(:project_id)).each do |project|
          project.with_lock do
            next if project.repository_storage != source_storage_name

            storage_move = project.repository_storage_moves.build(
              source_storage_name: source_storage_name,
              destination_storage_name: destination_storage_name
            )

            unless storage_move.schedule
              log_info("Project #{project.full_path} (#{project.id}) was skipped: #{storage_move.errors.full_messages.to_sentence}")
            end
          end
        end
      end

      success
    end

    def self.enqueue(source_storage_name, destination_storage_name = nil)
      ::ProjectScheduleBulkRepositoryShardMovesWorker.perform_async(source_storage_name, destination_storage_name)
    end
  end
end