Class: Ci::Refs::EnqueuePipelinesToUnlockService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/ci/refs/enqueue_pipelines_to_unlock_service.rb

Constant Summary collapse

BATCH_SIZE =
50
ENQUEUE_INTERVAL_SECONDS =
0.1
EXCLUDED_IDS_LIMIT =
1000

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?, #can_all?, #can_any?

Instance Method Details

#execute(ci_ref, before_pipeline: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/ci/refs/enqueue_pipelines_to_unlock_service.rb', line 12

def execute(ci_ref, before_pipeline: nil)
  total_new_entries = 0

  pipelines_scope(ci_ref, before_pipeline).each_batch(of: BATCH_SIZE) do |batch|
    pipeline_ids = batch.pluck(:id) # rubocop: disable CodeReuse/ActiveRecord
    total_added = Ci::UnlockPipelineRequest.enqueue(pipeline_ids)
    total_new_entries += total_added

    # Take a little rest to avoid overloading Redis
    sleep ENQUEUE_INTERVAL_SECONDS
  end

  success(
    total_pending_entries: Ci::UnlockPipelineRequest.total_pending,
    total_new_entries: total_new_entries
  )
end