Permalink
Browse files

Merge pull request #1495 from mperham/feature/race

Fixes a race condition which could result in a scheduled item being adde...
  • Loading branch information...
2 parents 7190f10 + cecfc7f commit 15111f32964158e450e743723ef2f0af5e5be311 @mperham committed Feb 18, 2014
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/sidekiq/api.rb
View
12 lib/sidekiq/api.rb
@@ -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 15111f3

Please sign in to comment.