Module: SidekiqUtils::EnqueuedJobsHelper

Defined in:
lib/sidekiq_utils/enqueued_jobs_helper.rb

Class Method Summary collapse

Class Method Details

.countsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sidekiq_utils/enqueued_jobs_helper.rb', line 4

def counts
  counts = {}
  Sidekiq::Queue.all.each do |queue|
    queue_job_counts = counts[queue.name] ||= {}
    queue.each do |job|
      job_key = SidekiqUtils::RedisMonitorStorage.job_prefix(
          job, unwrap_arguments: true)
      queue_job_counts[job_key] ||= 0
      queue_job_counts[job_key] += 1
    end
  end
  counts
end

.delete(queue:, job_class:, first_argument: nil) ⇒ Object



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
# File 'lib/sidekiq_utils/enqueued_jobs_helper.rb', line 18

def delete(queue:, job_class:, first_argument: nil)
  if job_class.is_a?(Class)
    job_class = job_class.name
  else
    job_class = job_class.to_s
  end

  deleted = 0
  Sidekiq::Queue.all.each do |iter_queue|
    next if queue && queue.to_s != iter_queue.name

    iter_queue.each do |job|
      next if job['class'] != job_class
      if first_argument && SidekiqUtils::AdditionalSerialization.
          unwrap_argument(job['args'].first) != first_argument
        next
      end

      job.delete
      deleted += 1
    end
  end

  deleted
end