mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
* Revert instance methods
* Add better test coverage
This commit is contained in:
parent
4dcbec2ba2
commit
187e6e90bd
2 changed files with 44 additions and 27 deletions
|
@ -3,33 +3,33 @@ require 'sidekiq'
|
|||
module Sidekiq
|
||||
|
||||
class Stats
|
||||
class << self
|
||||
def processed
|
||||
Sidekiq.redis do |conn|
|
||||
conn.get("stat:processed")
|
||||
end || 0
|
||||
end
|
||||
def processed
|
||||
count = Sidekiq.redis do |conn|
|
||||
conn.get("stat:processed")
|
||||
end
|
||||
count.nil? ? 0 : count.to_i
|
||||
end
|
||||
|
||||
def failed
|
||||
Sidekiq.redis do |conn|
|
||||
conn.get("stat:failed")
|
||||
end || 0
|
||||
end
|
||||
def failed
|
||||
count = Sidekiq.redis do |conn|
|
||||
conn.get("stat:failed")
|
||||
end
|
||||
count.nil? ? 0 : count.to_i
|
||||
end
|
||||
|
||||
def queues
|
||||
Sidekiq.redis do |conn|
|
||||
queues = conn.smembers('queues')
|
||||
def queues
|
||||
Sidekiq.redis do |conn|
|
||||
queues = conn.smembers('queues')
|
||||
|
||||
queues.inject({}) do |memo, queue|
|
||||
memo[queue] = conn.llen("queue:#{queue}")
|
||||
memo
|
||||
end
|
||||
queues.inject({}) do |memo, queue|
|
||||
memo[queue] = conn.llen("queue:#{queue}")
|
||||
memo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def enqueued
|
||||
queues.values.inject(&:+) || 0
|
||||
end
|
||||
def enqueued
|
||||
queues.values.inject(&:+) || 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,20 +8,34 @@ class TestApi < MiniTest::Unit::TestCase
|
|||
|
||||
describe "processed" do
|
||||
it "is initially zero" do
|
||||
assert_equal 0, Sidekiq::Stats.processed
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.processed
|
||||
end
|
||||
|
||||
it "returns number of processed jobs" do
|
||||
Sidekiq.redis { |conn| conn.set("stat:processed", 5) }
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 5, s.processed
|
||||
end
|
||||
end
|
||||
|
||||
describe "failed" do
|
||||
it "is initially zero" do
|
||||
assert_equal 0, Sidekiq::Stats.processed
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.processed
|
||||
end
|
||||
|
||||
it "returns number of failed jobs" do
|
||||
Sidekiq.redis { |conn| conn.set("stat:failed", 5) }
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 5, s.failed
|
||||
end
|
||||
end
|
||||
|
||||
describe "queues" do
|
||||
it "is initially empty" do
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, Sidekiq::Stats.queues.size
|
||||
assert_equal 0, s.queues.size
|
||||
end
|
||||
|
||||
it "returns a hash of queue and size" do
|
||||
|
@ -33,13 +47,15 @@ class TestApi < MiniTest::Unit::TestCase
|
|||
conn.sadd 'queues', 'bar'
|
||||
end
|
||||
|
||||
assert_equal ({ "foo" => 1, "bar" => 3 }), Sidekiq::Stats.queues
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal ({ "foo" => 1, "bar" => 3 }), s.queues
|
||||
end
|
||||
end
|
||||
|
||||
describe "enqueued" do
|
||||
it "is initially empty" do
|
||||
assert_equal 0, Sidekiq::Stats.enqueued
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.enqueued
|
||||
end
|
||||
|
||||
it "returns total enqueued jobs" do
|
||||
|
@ -51,7 +67,8 @@ class TestApi < MiniTest::Unit::TestCase
|
|||
conn.sadd 'queues', 'bar'
|
||||
end
|
||||
|
||||
assert_equal 4, Sidekiq::Stats.enqueued
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 4, s.enqueued
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue