Permalink
Browse files

Fixes a race condition which could result in a scheduled item being a…

…dded to the queue twice, or a retry being retried twice.
  • Loading branch information...
jonhyman committed Feb 18, 2014
1 parent 339e679 commit cecfc7f106bc7a5563782d73356915c8c56a1ccb
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/sidekiq/api.rb
View
@@ -231,8 +231,10 @@ def reschedule(at)
def add_to_queue
Sidekiq.redis do |conn|
- results = conn.zrangebyscore('schedule', score, score)
- conn.zremrangebyscore('schedule', score, score)
+ results = conn.multi do
+ conn.zrangebyscore('schedule', score, score)
+ conn.zremrangebyscore('schedule', score, score)
+ end.first
results.map do |message|
msg = Sidekiq.load_json(message)
Sidekiq::Client.push(msg)
@@ -243,8 +245,10 @@ def add_to_queue
def retry
raise "Retry not available on jobs not in the Retry queue." unless item["failed_at"]
Sidekiq.redis do |conn|
- results = conn.zrangebyscore('retry', score, score)
- conn.zremrangebyscore('retry', score, score)
+ results = conn.multi do
+ conn.zrangebyscore('retry', score, score)
+ conn.zremrangebyscore('retry', score, score)
+ end.first
results.map do |message|
msg = Sidekiq.load_json(message)
msg['retry_count'] = msg['retry_count'] - 1

0 comments on commit cecfc7f

Please sign in to comment.