Skip to content

Commit

Permalink
Refactor redis usage to avoid nil result from multi, see redis/redis-…
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Dec 18, 2014
1 parent c4fc6da commit ce3a26d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes.md
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
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

0 comments on commit ce3a26d

Please sign in to comment.