Module: ScheduleBulkRepositoryShardMovesMethods

Extended by:
ActiveSupport::Concern
Includes:
BaseServiceUtility
Included in:
Projects::ScheduleBulkRepositoryShardMovesService, Snippets::ScheduleBulkRepositoryShardMovesService
Defined in:
app/services/concerns/schedule_bulk_repository_shard_moves_methods.rb

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#execute(source_storage_name, destination_storage_name = nil) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/concerns/schedule_bulk_repository_shard_moves_methods.rb', line 17

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

  repository_klass.for_shard(shard).each_batch(column: container_column) do |relation|
    container_klass.id_in(relation.select(container_column)).each do |container|
      container.with_lock do
        next if container.repository_storage != source_storage_name

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

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

  success
end