mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge pull request #1495 from mperham/feature/race
Fixes a race condition which could result in a scheduled item being adde...
This commit is contained in:
commit
15111f3296
1 changed files with 8 additions and 4 deletions
|
@ -231,8 +231,10 @@ module Sidekiq
|
||||||
|
|
||||||
def add_to_queue
|
def add_to_queue
|
||||||
Sidekiq.redis do |conn|
|
Sidekiq.redis do |conn|
|
||||||
results = conn.zrangebyscore('schedule', score, score)
|
results = conn.multi do
|
||||||
|
conn.zrangebyscore('schedule', score, score)
|
||||||
conn.zremrangebyscore('schedule', score, score)
|
conn.zremrangebyscore('schedule', score, score)
|
||||||
|
end.first
|
||||||
results.map do |message|
|
results.map do |message|
|
||||||
msg = Sidekiq.load_json(message)
|
msg = Sidekiq.load_json(message)
|
||||||
Sidekiq::Client.push(msg)
|
Sidekiq::Client.push(msg)
|
||||||
|
@ -243,8 +245,10 @@ module Sidekiq
|
||||||
def retry
|
def retry
|
||||||
raise "Retry not available on jobs not in the Retry queue." unless item["failed_at"]
|
raise "Retry not available on jobs not in the Retry queue." unless item["failed_at"]
|
||||||
Sidekiq.redis do |conn|
|
Sidekiq.redis do |conn|
|
||||||
results = conn.zrangebyscore('retry', score, score)
|
results = conn.multi do
|
||||||
|
conn.zrangebyscore('retry', score, score)
|
||||||
conn.zremrangebyscore('retry', score, score)
|
conn.zremrangebyscore('retry', score, score)
|
||||||
|
end.first
|
||||||
results.map do |message|
|
results.map do |message|
|
||||||
msg = Sidekiq.load_json(message)
|
msg = Sidekiq.load_json(message)
|
||||||
msg['retry_count'] = msg['retry_count'] - 1
|
msg['retry_count'] = msg['retry_count'] - 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue