Permalink
Browse files

Add more testing for dead stuff

  • Loading branch information...
1 parent 2e1ffbc commit c063b624bf42b51eff5e237661d3b8ed23c56779 @mperham committed Feb 10, 2014
Showing with 46 additions and 19 deletions.
  1. +6 −4 Changes.md
  2. +17 −14 lib/sidekiq/api.rb
  3. +23 −1 test/test_web.rb
View
@@ -1,18 +1,20 @@
3.0.0
-----------
-- Dead Job Queue - jobs which run out of retries are now moved to a dead
+- **Dead Job Queue** - jobs which run out of retries are now moved to a dead
job queue. These jobs must be retried manually or they will expire
- after 6 months or 10,000 jobs.
+ after 6 months or 10,000 jobs. The Web UI contains a Dead tab
+ exposing these jobs.
- **Remove official support for Ruby 1.9** Things still might work but
I no longer actively test on it.
- Remove built-in support for Redis-to-Go.
Heroku users: `heroku config:set REDIS_PROVIDER=REDISTOGO_URL`
- Removed 'sidekiq/yaml\_patch', this was never documented or recommended.
- Removed the 'started' worker data, it originally provided compatibility with resque-web
but overlaps the 'run\_at' worker data.
-- Remove built-in error integration for Airbrake, Honeybadger, ExceptionNotifier and Exceptional.
- Just update your error gem to the latest version to pick up Sidekiq support.
+- **Remove built-in error integration for Airbrake, Honeybadger, ExceptionNotifier and Exceptional**.
+ Each error gem should provide its own Sidekiq integration. Update your error gem to the latest
+ version to pick up Sidekiq support.
- Remove deprecated Sidekiq::Client.registered\_\* APIs
- Remove deprecated support for the old Sidekiq::Worker#retries\_exhausted method.
View
@@ -213,6 +213,7 @@ def [](name)
class SortedEntry < Job
attr_reader :score
+ attr_reader :parent
def initialize(parent, score, item)
super(item)
@@ -245,10 +246,10 @@ def add_to_queue
end
def retry
- raise "Retry not available on jobs not in the Retry queue." unless item["failed_at"]
+ raise "Retry not available on jobs which have not failed" unless item["failed_at"]
Sidekiq.redis do |conn|
- results = conn.zrangebyscore('retry', score, score)
- conn.zremrangebyscore('retry', score, score)
+ results = conn.zrangebyscore(parent.name, score, score)
+ conn.zremrangebyscore(parent.name, score, score)
results.map do |message|
msg = Sidekiq.load_json(message)
msg['retry_count'] = msg['retry_count'] - 1
@@ -261,18 +262,20 @@ def retry
class SortedSet
include Enumerable
+ attr_reader :name
+
def initialize(name)
- @zset = name
+ @name = name
@_size = size
end
def size
- Sidekiq.redis {|c| c.zcard(@zset) }
+ Sidekiq.redis {|c| c.zcard(name) }
end
def schedule(timestamp, message)
Sidekiq.redis do |conn|
- conn.zadd(@zset, timestamp.to_f.to_s, Sidekiq.dump_json(message))
+ conn.zadd(name, timestamp.to_f.to_s, Sidekiq.dump_json(message))
end
end
@@ -286,7 +289,7 @@ def each(&block)
range_start = page * page_size + offset_size
range_end = page * page_size + offset_size + (page_size - 1)
elements = Sidekiq.redis do |conn|
- conn.zrange @zset, range_start, range_end, :with_scores => true
+ conn.zrange name, range_start, range_end, :with_scores => true
end
break if elements.empty?
page -= 1
@@ -299,7 +302,7 @@ def each(&block)
def fetch(score, jid = nil)
elements = Sidekiq.redis do |conn|
- conn.zrangebyscore(@zset, score, score)
+ conn.zrangebyscore(name, score, score)
end
elements.inject([]) do |result, element|
@@ -320,7 +323,7 @@ def find_job(jid)
def delete(score, jid = nil)
if jid
elements = Sidekiq.redis do |conn|
- conn.zrangebyscore(@zset, score, score)
+ conn.zrangebyscore(name, score, score)
end
elements_with_jid = elements.map do |element|
@@ -329,8 +332,8 @@ def delete(score, jid = nil)
if message["jid"] == jid
_, @_size = Sidekiq.redis do |conn|
conn.multi do
- conn.zrem(@zset, element)
- conn.zcard @zset
+ conn.zrem(name, element)
+ conn.zcard name
end
end
end
@@ -339,8 +342,8 @@ def delete(score, jid = nil)
else
count, @_size = Sidekiq.redis do |conn|
conn.multi do
- conn.zremrangebyscore(@zset, score, score)
- conn.zcard @zset
+ conn.zremrangebyscore(name, score, score)
+ conn.zcard name
end
end
count != 0
@@ -349,7 +352,7 @@ def delete(score, jid = nil)
def clear
Sidekiq.redis do |conn|
- conn.del(@zset)
+ conn.del(name)
end
end
end
View
@@ -397,12 +397,34 @@ def perform(a, b)
get 'morgue'
assert_equal 200, last_response.status
end
+
it 'shows index with jobs' do
(_, score) = add_dead
get 'morgue'
assert_equal 200, last_response.status
assert_match /#{score}/, last_response.body
end
+
+ it 'can delete all dead' do
+ 3.times { add_dead }
+
+ assert_equal 3, Sidekiq::DeadSet.new.size
+ post "/morgue/all/delete", 'delete' => 'Delete'
+ assert_equal 0, Sidekiq::DeadSet.new.size
+ assert_equal 302, last_response.status
+ assert_equal 'http://example.org/morgue', last_response.header['Location']
+ end
+
+ it 'can retry a dead job' do
+ params = add_dead
+ post "/morgue/#{job_params(*params)}", 'retry' => 'Retry'
+ assert_equal 302, last_response.status
+ assert_equal 'http://example.org/morgue', last_response.header['Location']
+
+ get '/queues/foo'
+ assert_equal 200, last_response.status
+ assert_match /#{params.first['args'][2]}/, last_response.body
+ end
end
def add_scheduled
@@ -435,7 +457,7 @@ def add_retry
def add_dead
msg = { 'class' => 'HardWorker',
'args' => ['bob', 1, Time.now.to_f],
- 'queue' => 'default',
+ 'queue' => 'foo',
'error_message' => 'Some fake message',
'error_class' => 'RuntimeError',
'retry_count' => 0,

0 comments on commit c063b62

Please sign in to comment.