Class: Sidekiq::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/api.rb

Defined Under Namespace

Classes: History

Instance Method Summary collapse

Instance Method Details

#dead_sizeObject



61
62
63
# File 'lib/sidekiq/api.rb', line 61

def dead_size
  Sidekiq.redis {|c| c.zcard('dead') }
end

#enqueuedObject



49
50
51
# File 'lib/sidekiq/api.rb', line 49

def enqueued
  queues.values.inject(&:+) || 0
end

#failedObject



10
11
12
# File 'lib/sidekiq/api.rb', line 10

def failed
  Sidekiq.redis { |conn| conn.get("stat:failed") }.to_i
end

#processedObject



6
7
8
# File 'lib/sidekiq/api.rb', line 6

def processed
  Sidekiq.redis { |conn| conn.get("stat:processed") }.to_i
end

#queuesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sidekiq/api.rb', line 28

def queues
  Sidekiq.redis do |conn|
    queues = conn.smembers('queues')

    lengths = conn.pipelined do
      queues.each do |queue|
        conn.llen("queue:#{queue}")
      end
    end

    i = 0
    array_of_arrays = queues.inject({}) do |memo, queue|
      memo[queue] = lengths[i]
      i += 1
      memo
    end.sort_by { |_, size| size }

    Hash[array_of_arrays.reverse]
  end
end

#reset(*stats) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidekiq/api.rb', line 14

def reset(*stats)
  all   = %w(failed processed)
  stats = stats.empty? ? all : all & stats.flatten.compact.map(&:to_s)

  mset_args = []
  stats.each do |stat|
    mset_args << "stat:#{stat}"
    mset_args << 0
  end
  Sidekiq.redis do |conn|
    conn.mset(*mset_args)
  end
end

#retry_sizeObject



57
58
59
# File 'lib/sidekiq/api.rb', line 57

def retry_size
  Sidekiq.redis {|c| c.zcard('retry') }
end

#scheduled_sizeObject



53
54
55
# File 'lib/sidekiq/api.rb', line 53

def scheduled_size
  Sidekiq.redis {|c| c.zcard('schedule') }
end