2012-10-20 17:03:43 -04:00
|
|
|
require 'helper'
|
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
class TestApi < Sidekiq::Test
|
2014-03-02 19:36:00 -05:00
|
|
|
|
2012-12-04 08:11:25 -05:00
|
|
|
describe "stats" do
|
|
|
|
before do
|
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "processed" do
|
|
|
|
it "is initially zero" do
|
2012-12-04 13:14:38 -05:00
|
|
|
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
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "failed" do
|
|
|
|
it "is initially zero" do
|
2012-12-04 13:14:38 -05:00
|
|
|
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
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-30 18:16:21 -04:00
|
|
|
describe "reset" do
|
2013-12-18 10:46:41 -05:00
|
|
|
before do
|
2013-04-30 18:16:21 -04:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.set('stat:processed', 5)
|
|
|
|
conn.set('stat:failed', 10)
|
2013-12-18 10:46:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'will reset all stats by default' do
|
|
|
|
Sidekiq::Stats.new.reset
|
|
|
|
Sidekiq.redis do |conn|
|
2013-04-30 18:16:21 -04:00
|
|
|
assert_equal '0', conn.get('stat:processed')
|
|
|
|
assert_equal '0', conn.get('stat:failed')
|
|
|
|
end
|
|
|
|
end
|
2013-12-18 10:46:41 -05:00
|
|
|
|
|
|
|
it 'can reset individual stats' do
|
|
|
|
Sidekiq::Stats.new.reset('failed')
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
assert_equal '5', conn.get('stat:processed')
|
|
|
|
assert_equal '0', conn.get('stat:failed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can accept anything that responds to #to_s' do
|
|
|
|
Sidekiq::Stats.new.reset(:failed)
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
assert_equal '5', conn.get('stat:processed')
|
|
|
|
assert_equal '0', conn.get('stat:failed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores anything other than "failed" or "processed"' do
|
|
|
|
Sidekiq::Stats.new.reset((1..10).to_a, ['failed'])
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
assert_equal '5', conn.get('stat:processed')
|
|
|
|
assert_equal '0', conn.get('stat:failed')
|
|
|
|
end
|
|
|
|
end
|
2013-04-30 18:16:21 -04:00
|
|
|
end
|
|
|
|
|
2012-12-04 08:11:25 -05:00
|
|
|
describe "queues" do
|
|
|
|
it "is initially empty" do
|
|
|
|
s = Sidekiq::Stats.new
|
2012-12-04 13:14:38 -05:00
|
|
|
assert_equal 0, s.queues.size
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
|
2012-12-04 17:05:47 -05:00
|
|
|
it "returns a hash of queue and size in order" do
|
2012-12-04 08:11:25 -05:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.rpush 'queue:foo', '{}'
|
|
|
|
conn.sadd 'queues', 'foo'
|
|
|
|
|
|
|
|
3.times { conn.rpush 'queue:bar', '{}' }
|
|
|
|
conn.sadd 'queues', 'bar'
|
|
|
|
end
|
|
|
|
|
2012-12-04 13:14:38 -05:00
|
|
|
s = Sidekiq::Stats.new
|
|
|
|
assert_equal ({ "foo" => 1, "bar" => 3 }), s.queues
|
2012-12-04 17:05:47 -05:00
|
|
|
assert_equal "bar", s.queues.first.first
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-04 12:18:05 -05:00
|
|
|
describe "enqueued" do
|
2012-12-04 08:11:25 -05:00
|
|
|
it "is initially empty" do
|
2012-12-04 13:14:38 -05:00
|
|
|
s = Sidekiq::Stats.new
|
|
|
|
assert_equal 0, s.enqueued
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
|
2012-12-04 12:18:05 -05:00
|
|
|
it "returns total enqueued jobs" do
|
2012-12-04 08:11:25 -05:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.rpush 'queue:foo', '{}'
|
|
|
|
conn.sadd 'queues', 'foo'
|
|
|
|
|
|
|
|
3.times { conn.rpush 'queue:bar', '{}' }
|
|
|
|
conn.sadd 'queues', 'bar'
|
|
|
|
end
|
|
|
|
|
2012-12-04 13:14:38 -05:00
|
|
|
s = Sidekiq::Stats.new
|
|
|
|
assert_equal 4, s.enqueued
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
end
|
2012-12-05 20:35:49 -05:00
|
|
|
|
|
|
|
describe "over time" do
|
|
|
|
describe "processed" do
|
|
|
|
it 'retrieves hash of dates' do
|
|
|
|
Sidekiq.redis do |c|
|
|
|
|
c.incrby("stat:processed:2012-12-24", 4)
|
|
|
|
c.incrby("stat:processed:2012-12-25", 1)
|
|
|
|
c.incrby("stat:processed:2012-12-26", 6)
|
|
|
|
c.incrby("stat:processed:2012-12-27", 2)
|
|
|
|
end
|
|
|
|
Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
|
|
|
|
s = Sidekiq::Stats::History.new(2)
|
|
|
|
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.processed
|
|
|
|
|
|
|
|
s = Sidekiq::Stats::History.new(3)
|
|
|
|
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
|
|
|
|
|
|
|
s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
|
|
|
|
assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "failed" do
|
|
|
|
it 'retrieves hash of dates' do
|
|
|
|
Sidekiq.redis do |c|
|
|
|
|
c.incrby("stat:failed:2012-12-24", 4)
|
|
|
|
c.incrby("stat:failed:2012-12-25", 1)
|
|
|
|
c.incrby("stat:failed:2012-12-26", 6)
|
|
|
|
c.incrby("stat:failed:2012-12-27", 2)
|
|
|
|
end
|
|
|
|
Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
|
|
|
|
s = Sidekiq::Stats::History.new(2)
|
|
|
|
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.failed
|
|
|
|
|
|
|
|
s = Sidekiq::Stats::History.new(3)
|
|
|
|
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.failed
|
|
|
|
|
|
|
|
s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
|
|
|
|
assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.failed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-04 08:11:25 -05:00
|
|
|
end
|
|
|
|
|
2012-10-20 17:03:43 -04:00
|
|
|
describe 'with an empty database' do
|
2014-03-02 19:36:00 -05:00
|
|
|
include Sidekiq::Util
|
|
|
|
|
2012-10-20 17:03:43 -04:00
|
|
|
before do
|
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows queue as empty' do
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
assert_equal 0, q.size
|
2013-05-24 01:58:06 -04:00
|
|
|
assert_equal 0, q.latency
|
2012-10-20 17:03:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class ApiWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can enumerate jobs' do
|
2013-05-24 01:58:06 -04:00
|
|
|
q = Sidekiq::Queue.new
|
2013-05-23 07:31:41 -04:00
|
|
|
Time.stub(:now, Time.new(2012, 12, 26)) do
|
|
|
|
ApiWorker.perform_async(1, 'mike')
|
|
|
|
assert_equal ['TestApi::ApiWorker'], q.map(&:klass)
|
|
|
|
|
|
|
|
job = q.first
|
|
|
|
assert_equal 24, job.jid.size
|
|
|
|
assert_equal [1, 'mike'], job.args
|
|
|
|
assert_equal Time.new(2012, 12, 26), job.enqueued_at
|
|
|
|
|
|
|
|
end
|
2013-05-24 01:58:06 -04:00
|
|
|
|
|
|
|
assert q.latency > 10_000_000
|
|
|
|
|
|
|
|
q = Sidekiq::Queue.new('other')
|
|
|
|
assert_equal 0, q.size
|
2012-10-20 17:03:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can delete jobs' do
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
ApiWorker.perform_async(1, 'mike')
|
|
|
|
assert_equal 1, q.size
|
|
|
|
assert_equal [true], q.map(&:delete)
|
|
|
|
assert_equal 0, q.size
|
|
|
|
end
|
|
|
|
|
2013-06-23 18:57:52 -04:00
|
|
|
it "can move scheduled job to queue" do
|
|
|
|
job_id = ApiWorker.perform_in(100, 1, 'jason')
|
|
|
|
job = Sidekiq::ScheduledSet.new.find_job(job_id)
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
job.add_to_queue
|
|
|
|
queued_job = q.find_job(job_id)
|
|
|
|
refute_nil queued_job
|
|
|
|
assert_equal queued_job.jid, job_id
|
|
|
|
job = Sidekiq::ScheduledSet.new.find_job(job_id)
|
|
|
|
assert_nil job
|
|
|
|
end
|
|
|
|
|
2013-04-17 14:11:29 -04:00
|
|
|
it 'can find job by id in sorted sets' do
|
2013-04-16 15:43:24 -04:00
|
|
|
job_id = ApiWorker.perform_in(100, 1, 'jason')
|
2013-04-17 14:11:29 -04:00
|
|
|
job = Sidekiq::ScheduledSet.new.find_job(job_id)
|
|
|
|
refute_nil job
|
|
|
|
assert_equal job_id, job.jid
|
2013-05-24 22:59:40 -04:00
|
|
|
assert_in_delta job.latency, 0.0, 0.01
|
2013-04-17 14:11:29 -04:00
|
|
|
end
|
|
|
|
|
2013-10-10 22:27:47 -04:00
|
|
|
it 'can remove jobs when iterating over a sorted set' do
|
|
|
|
# scheduled jobs must be greater than SortedSet#each underlying page size
|
|
|
|
51.times do
|
|
|
|
ApiWorker.perform_in(100, 'aaron')
|
|
|
|
end
|
|
|
|
set = Sidekiq::ScheduledSet.new
|
|
|
|
set.map(&:delete)
|
|
|
|
assert_equal set.size, 0
|
|
|
|
end
|
|
|
|
|
2013-10-12 18:56:34 -04:00
|
|
|
it 'can remove jobs when iterating over a queue' do
|
|
|
|
# initial queue size must be greater than Queue#each underlying page size
|
|
|
|
51.times do
|
|
|
|
ApiWorker.perform_async(1, 'aaron')
|
|
|
|
end
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
q.map(&:delete)
|
|
|
|
assert_equal q.size, 0
|
|
|
|
end
|
|
|
|
|
2013-04-17 14:11:29 -04:00
|
|
|
it 'can find job by id in queues' do
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
job_id = ApiWorker.perform_async(1, 'jason')
|
|
|
|
job = q.find_job(job_id)
|
|
|
|
refute_nil job
|
|
|
|
assert_equal job_id, job.jid
|
2013-04-16 15:43:24 -04:00
|
|
|
end
|
|
|
|
|
2012-11-25 21:43:48 -05:00
|
|
|
it 'can clear a queue' do
|
|
|
|
q = Sidekiq::Queue.new
|
|
|
|
2.times { ApiWorker.perform_async(1, 'mike') }
|
|
|
|
q.clear
|
|
|
|
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
refute conn.smembers('queues').include?('foo')
|
|
|
|
refute conn.exists('queues:foo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-02 23:32:16 -05:00
|
|
|
it 'can fetch by score' do
|
|
|
|
same_time = Time.now.to_f
|
|
|
|
add_retry('bob1', same_time)
|
|
|
|
add_retry('bob2', same_time)
|
|
|
|
r = Sidekiq::RetrySet.new
|
|
|
|
assert_equal 2, r.fetch(same_time).size
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can fetch by score and jid' do
|
|
|
|
same_time = Time.now.to_f
|
|
|
|
add_retry('bob1', same_time)
|
|
|
|
add_retry('bob2', same_time)
|
|
|
|
r = Sidekiq::RetrySet.new
|
|
|
|
# jobs = r.fetch(same_time)
|
|
|
|
# puts jobs[1].jid
|
|
|
|
assert_equal 1, r.fetch(same_time, 'bob1').size
|
|
|
|
end
|
|
|
|
|
2012-10-20 17:03:43 -04:00
|
|
|
it 'shows empty retries' do
|
2012-10-30 13:06:20 -04:00
|
|
|
r = Sidekiq::RetrySet.new
|
2012-10-20 17:03:43 -04:00
|
|
|
assert_equal 0, r.size
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can enumerate retries' do
|
|
|
|
add_retry
|
|
|
|
|
2012-10-30 13:06:20 -04:00
|
|
|
r = Sidekiq::RetrySet.new
|
2012-10-20 17:03:43 -04:00
|
|
|
assert_equal 1, r.size
|
|
|
|
array = r.to_a
|
|
|
|
assert_equal 1, array.size
|
|
|
|
|
|
|
|
retri = array.first
|
|
|
|
assert_equal 'ApiWorker', retri.klass
|
|
|
|
assert_equal 'default', retri.queue
|
|
|
|
assert_equal 'bob', retri.jid
|
2014-05-13 17:24:52 -04:00
|
|
|
assert_in_delta Time.now.to_f, retri.at.to_f, 0.02
|
2012-10-20 17:03:43 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
it 'can delete multiple retries from score' do
|
|
|
|
same_time = Time.now.to_f
|
|
|
|
add_retry('bob1', same_time)
|
|
|
|
add_retry('bob2', same_time)
|
2012-10-30 13:06:20 -04:00
|
|
|
r = Sidekiq::RetrySet.new
|
2012-11-26 14:53:22 -05:00
|
|
|
assert_equal 2, r.size
|
|
|
|
Sidekiq::RetrySet.new.delete(same_time)
|
2012-10-20 17:03:43 -04:00
|
|
|
assert_equal 0, r.size
|
|
|
|
end
|
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
it 'can delete a single retry from score and jid' do
|
2012-11-26 12:56:08 -05:00
|
|
|
same_time = Time.now.to_f
|
|
|
|
add_retry('bob1', same_time)
|
|
|
|
add_retry('bob2', same_time)
|
|
|
|
r = Sidekiq::RetrySet.new
|
|
|
|
assert_equal 2, r.size
|
2012-11-26 14:53:22 -05:00
|
|
|
Sidekiq::RetrySet.new.delete(same_time, 'bob1')
|
2012-11-26 12:56:08 -05:00
|
|
|
assert_equal 1, r.size
|
|
|
|
end
|
|
|
|
|
2012-11-26 11:22:48 -05:00
|
|
|
it 'can retry a retry' do
|
|
|
|
add_retry
|
|
|
|
r = Sidekiq::RetrySet.new
|
|
|
|
assert_equal 1, r.size
|
|
|
|
r.first.retry
|
|
|
|
assert_equal 0, r.size
|
|
|
|
assert_equal 1, Sidekiq::Queue.new('default').size
|
|
|
|
job = Sidekiq::Queue.new('default').first
|
|
|
|
assert_equal 'bob', job.jid
|
|
|
|
assert_equal 1, job['retry_count']
|
|
|
|
end
|
|
|
|
|
2012-11-25 21:43:48 -05:00
|
|
|
it 'can clear retries' do
|
|
|
|
add_retry
|
|
|
|
add_retry('test')
|
|
|
|
r = Sidekiq::RetrySet.new
|
|
|
|
assert_equal 2, r.size
|
|
|
|
r.clear
|
|
|
|
assert_equal 0, r.size
|
|
|
|
end
|
|
|
|
|
2014-03-03 00:18:26 -05:00
|
|
|
it 'can enumerate processes' do
|
2014-03-08 01:41:10 -05:00
|
|
|
odata = { 'pid' => 123, 'hostname' => hostname, 'key' => "#{hostname}:123", 'started_at' => Time.now.to_f - 15 }
|
|
|
|
time = Time.now.to_f
|
2014-03-03 00:18:26 -05:00
|
|
|
Sidekiq.redis do |conn|
|
2014-03-08 01:41:10 -05:00
|
|
|
conn.multi do
|
|
|
|
conn.sadd('processes', odata['key'])
|
2014-03-08 16:57:24 -05:00
|
|
|
conn.hmset(odata['key'], 'info', Sidekiq.dump_json(odata), 'busy', 10, 'beat', time)
|
2014-03-08 01:41:10 -05:00
|
|
|
conn.sadd('processes', 'fake:pid')
|
|
|
|
end
|
2014-03-03 00:18:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
ps = Sidekiq::ProcessSet.new.to_a
|
|
|
|
assert_equal 1, ps.size
|
|
|
|
data = ps.first
|
2014-05-13 23:33:20 -04:00
|
|
|
assert_equal 10, data['busy']
|
|
|
|
assert_equal time, data['beat']
|
|
|
|
assert_equal 123, data['pid']
|
2014-05-16 00:12:44 -04:00
|
|
|
data.quiet!
|
|
|
|
data.stop!
|
|
|
|
assert_equal "TERM", Sidekiq.redis{|c| c.lpop("#{hostname}:123-signals") }
|
|
|
|
assert_equal "USR1", Sidekiq.redis{|c| c.lpop("#{hostname}:123-signals") }
|
2014-03-03 00:18:26 -05:00
|
|
|
end
|
|
|
|
|
2013-01-24 12:50:30 -05:00
|
|
|
it 'can enumerate workers' do
|
|
|
|
w = Sidekiq::Workers.new
|
|
|
|
assert_equal 0, w.size
|
2013-03-22 00:46:46 -04:00
|
|
|
w.each do
|
2013-01-24 12:50:30 -05:00
|
|
|
assert false
|
|
|
|
end
|
|
|
|
|
2014-03-08 17:44:19 -05:00
|
|
|
key = "#{hostname}:#{$$}"
|
|
|
|
pdata = { 'pid' => $$, 'hostname' => hostname, 'started_at' => Time.now.to_i }
|
2014-03-02 19:36:00 -05:00
|
|
|
Sidekiq.redis do |conn|
|
2014-03-08 17:44:19 -05:00
|
|
|
conn.sadd('processes', key)
|
|
|
|
conn.hmset(key, 'info', Sidekiq.dump_json(pdata), 'busy', 0, 'beat', Time.now.to_f)
|
2014-03-02 19:36:00 -05:00
|
|
|
end
|
2014-03-03 00:18:26 -05:00
|
|
|
|
2014-03-08 17:44:19 -05:00
|
|
|
s = "#{key}:workers"
|
2013-01-24 12:50:30 -05:00
|
|
|
data = Sidekiq.dump_json({ 'payload' => {}, 'queue' => 'default', 'run_at' => Time.now.to_i })
|
2013-04-17 14:11:29 -04:00
|
|
|
Sidekiq.redis do |c|
|
2014-03-08 01:41:10 -05:00
|
|
|
c.hmset(s, '1234', data)
|
|
|
|
end
|
|
|
|
|
2014-03-08 17:44:19 -05:00
|
|
|
w.each do |p, x, y|
|
|
|
|
assert_equal key, p
|
2014-03-08 01:41:10 -05:00
|
|
|
assert_equal "1234", x
|
2013-01-24 12:50:30 -05:00
|
|
|
assert_equal 'default', y['queue']
|
2014-02-01 23:48:44 -05:00
|
|
|
assert_equal Time.now.year, Time.at(y['run_at']).year
|
2013-01-24 12:50:30 -05:00
|
|
|
end
|
2014-02-28 00:15:08 -05:00
|
|
|
|
2014-03-08 17:44:19 -05:00
|
|
|
s = "#{key}:workers"
|
2014-02-28 00:15:08 -05:00
|
|
|
data = Sidekiq.dump_json({ 'payload' => {}, 'queue' => 'default', 'run_at' => (Time.now.to_i - 2*60*60) })
|
|
|
|
Sidekiq.redis do |c|
|
|
|
|
c.multi do
|
2014-03-08 01:41:10 -05:00
|
|
|
c.hmset(s, '5678', data)
|
|
|
|
c.hmset("b#{s}", '5678', data)
|
2014-02-28 00:15:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-19 20:11:12 -04:00
|
|
|
assert_equal ['1234', '5678'], w.map { |_, tid, _| tid }
|
2013-01-24 12:50:30 -05:00
|
|
|
end
|
|
|
|
|
2013-01-29 16:17:59 -05:00
|
|
|
it 'can reschedule jobs' do
|
|
|
|
add_retry('foo1')
|
|
|
|
add_retry('foo2')
|
|
|
|
|
|
|
|
retries = Sidekiq::RetrySet.new
|
|
|
|
assert_equal 2, retries.size
|
|
|
|
refute(retries.map { |r| r.score > (Time.now.to_f + 9) }.any?)
|
|
|
|
|
|
|
|
retries.each do |retri|
|
|
|
|
retri.reschedule(Time.now.to_f + 10) if retri.jid == 'foo2'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 2, retries.size
|
|
|
|
assert(retries.map { |r| r.score > (Time.now.to_f + 9) }.any?)
|
|
|
|
end
|
|
|
|
|
2014-03-09 17:32:27 -04:00
|
|
|
it 'prunes processes which have died' do
|
|
|
|
data = { 'pid' => rand(10_000), 'hostname' => "app#{rand(1_000)}", 'started_at' => Time.now.to_f }
|
|
|
|
key = "#{data['hostname']}:#{data['pid']}"
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.sadd('processes', key)
|
|
|
|
conn.hmset(key, 'info', Sidekiq.dump_json(data), 'busy', 0, 'beat', Time.now.to_f)
|
|
|
|
end
|
|
|
|
|
|
|
|
ps = Sidekiq::ProcessSet.new
|
|
|
|
assert_equal 1, ps.size
|
|
|
|
assert_equal 1, ps.to_a.size
|
|
|
|
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.sadd('processes', "bar:987")
|
|
|
|
conn.sadd('processes', "bar:986")
|
|
|
|
end
|
|
|
|
|
|
|
|
ps = Sidekiq::ProcessSet.new
|
|
|
|
assert_equal 3, ps.size
|
|
|
|
assert_equal 1, ps.to_a.size
|
|
|
|
end
|
|
|
|
|
2012-11-26 12:56:08 -05:00
|
|
|
def add_retry(jid = 'bob', at = Time.now.to_f)
|
2014-02-09 18:08:21 -05:00
|
|
|
payload = Sidekiq.dump_json('class' => 'ApiWorker', 'args' => [1, 'mike'], 'queue' => 'default', 'jid' => jid, 'retry_count' => 2, 'failed_at' => Time.now.to_f)
|
2012-10-20 17:03:43 -04:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('retry', at.to_s, payload)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|