Skip to content

Commit

Permalink
Merge pull request sidekiq#2094 from mperham/fix_nil_multi
Browse files Browse the repository at this point in the history
Refactor redis usage to avoid nil result from multi, see redis/redis-rb#490
  • Loading branch information
mperham committed Dec 18, 2014
2 parents b5899c7 + 6555e54 commit 50f9575
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ HEAD
-----------

- Log Sidekiq Pro's Batch ID if available [#2076]
- Refactor Processor Redis usage to avoid redis/redis-rb#490 [#]


3.3.0
Expand Down
12 changes: 6 additions & 6 deletions lib/sidekiq/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ def stats(worker, msg, queue)
yield
rescue Exception
retry_and_suppress_exceptions do
failed = "stat:failed:#{Time.now.utc.to_date}"
Sidekiq.redis do |conn|
failed = "stat:failed:#{Time.now.utc.to_date}"
result = conn.multi do
conn.multi do
conn.incrby("stat:failed", 1)
conn.incrby(failed, 1)
conn.expire(failed, STATS_TIMEOUT)
end
conn.expire(failed, STATS_TIMEOUT) if result.last == 1
end
end
raise
ensure
retry_and_suppress_exceptions do
processed = "stat:processed:#{Time.now.utc.to_date}"
Sidekiq.redis do |conn|
processed = "stat:processed:#{Time.now.utc.to_date}"
result = conn.multi do
conn.multi do
conn.hdel("#{identity}:workers", thread_identity)
conn.incrby("stat:processed", 1)
conn.incrby(processed, 1)
conn.expire(processed, STATS_TIMEOUT)
end
conn.expire(processed, STATS_TIMEOUT) if result.last == 1
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def new_manager(opts)
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
assert_equal ["1"], info
expires = Sidekiq.redis { |c| c.pttl('identity') }
assert_in_delta 60000, expires, 10
assert_in_delta 60000, expires, 50
end
end

Expand Down

0 comments on commit 50f9575

Please sign in to comment.