Class: Gitlab::SidekiqQueue

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/sidekiq_queue.rb

Constant Summary collapse

NoMetadataError =
Class.new(StandardError)
InvalidQueueError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(queue_name) ⇒ SidekiqQueue

Returns a new instance of SidekiqQueue.


12
13
14
# File 'lib/gitlab/sidekiq_queue.rb', line 12

def initialize(queue_name)
  @queue_name = queue_name
end

Instance Attribute Details

#queue_nameObject (readonly)

Returns the value of attribute queue_name


10
11
12
# File 'lib/gitlab/sidekiq_queue.rb', line 10

def queue_name
  @queue_name
end

Instance Method Details

#drop_jobs!(search_metadata, timeout:) ⇒ Object

Raises:


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/sidekiq_queue.rb', line 16

def drop_jobs!(, timeout:)
  start_time = Gitlab::Metrics::System.monotonic_time
  completed = true
  deleted_jobs = 0

   =
    
      .stringify_keys
      .slice(*Labkit::Context::KNOWN_KEYS)
      .transform_keys { |key| "meta.#{key}" }
      .compact

  raise NoMetadataError if .empty?
  raise InvalidQueueError unless queue

  queue.each do |job|
    if timeout_exceeded?(start_time, timeout)
      completed = false
      break
    end

    next unless job_matches?(job, )

    job.delete
    deleted_jobs += 1
  end

  {
    completed: completed,
    deleted_jobs: deleted_jobs,
    queue_size: queue.size
  }
end