Skip to content

Loading…

Fixes a race condition which could result in a scheduled item being adde... #1495

Merged
merged 1 commit into from

2 participants

@jonhyman
Collaborator

...d to the queue twice, or a retry being retried twice.

@jonhyman jonhyman Fixes a race condition which could result in a scheduled item being a…
…dded to the queue twice, or a retry being retried twice.
cecfc7f
@mperham mperham merged commit 15111f3 into master

1 check passed

Details default The Travis CI build passed
@mperham mperham deleted the feature/race branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2014
  1. @jonhyman

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

    jonhyman committed
    …dded to the queue twice, or a retry being retried twice.
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
Something went wrong with that request. Please try again.