1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Implement Sidekiq::Stats.processed

This commit is contained in:
jc00ke 2012-09-03 10:37:54 -07:00
parent 3a29555553
commit ec4833b0da
5 changed files with 16 additions and 6 deletions

View file

@ -20,7 +20,7 @@ end
get '/' do
@failed = $redis.get('stat:failed')
@processed = $redis.get('stat:processed')
@processed = Sidekiq::Stats.processed
@messages = $redis.lrange('sinkiq-example-messages', 0, -1)
erb :index
end

View file

@ -4,6 +4,7 @@ require 'sidekiq/client'
require 'sidekiq/worker'
require 'sidekiq/redis_connection'
require 'sidekiq/util'
require 'sidekiq/stats'
require 'sidekiq/extensions/class_methods'
require 'sidekiq/extensions/action_mailer'

9
lib/sidekiq/stats.rb Normal file
View file

@ -0,0 +1,9 @@
module Sidekiq
module Stats
module_function
def processed
Sidekiq.redis { |conn| conn.get('stat:processed') }.to_i || 0
end
end
end

View file

@ -61,7 +61,7 @@ module Sidekiq
end
def processed
Sidekiq.redis { |conn| conn.get('stat:processed') } || 0
Sidekiq::Stats.processed
end
def failed

View file

@ -32,14 +32,14 @@ class TestStats < MiniTest::Unit::TestCase
boss.expect(:processor_done!, nil, [processor])
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 0, conn.get('stat:processed').to_i
assert_equal 0, Sidekiq::Stats.processed
processor.process(msg, 'xyzzy')
processor.process(msg, 'xyzzy')
processor.process(msg, 'xyzzy')
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 3, conn.get('stat:processed').to_i
assert_equal 3, Sidekiq::Stats.processed
end
end
@ -50,7 +50,7 @@ class TestStats < MiniTest::Unit::TestCase
@redis.with do |conn|
assert_equal [], conn.smembers('workers')
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 0, conn.get('stat:processed').to_i
assert_equal 0, Sidekiq::Stats.processed
processor = Sidekiq::Processor.new(boss)
@ -60,7 +60,7 @@ class TestStats < MiniTest::Unit::TestCase
end
assert_equal 1, conn.get('stat:failed').to_i
assert_equal 1, conn.get('stat:processed').to_i
assert_equal 1, Sidekiq::Stats.processed
end
end