Class: WorkItems::ProcessGroupTransferEventsWorker

Inherits:
Object
  • Object
show all
Includes:
Gitlab::EventStore::Subscriber
Defined in:
app/workers/work_items/process_group_transfer_events_worker.rb

Constant Summary collapse

BATCH_SIZE =
100

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::EventStore::Subscriber

#handle_event_in, #perform

Class Method Details

.handles_event?(event) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/workers/work_items/process_group_transfer_events_worker.rb', line 17

def self.handles_event?(event)
  Group.exists?(event.data[:group_id]) # rubocop: disable CodeReuse/ActiveRecord -- no need to initialize an object to find the Group
end

Instance Method Details

#handle_event(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/workers/work_items/process_group_transfer_events_worker.rb', line 21

def handle_event(event)
  group = Group.find_by_id(event.data[:group_id])
  return unless group

  iterator = Gitlab::Database::NamespaceEachBatch
               .new(namespace_class: Namespace, cursor: { current_id: group.id, depth: [group.id] })

  iterator.each_batch(of: BATCH_SIZE) do |namespace_ids|
    break unless namespace_ids.present?

    WorkItems::UpdateNamespaceTraversalIdsWorker.bulk_perform_async_with_contexts(
      namespace_ids,
      arguments_proc: ->(namespace_id) { namespace_id },
      context_proc: ->(_) { {} } # No namespace context because loading the namespace is wasteful
    )
  end
end