Skip to content

Commit

Permalink
Do not connect to redis at exit if not needed
Browse files Browse the repository at this point in the history
A fix for #4498 introduced
a call-back that is executed at ruby VM exit and tries to connect to redis.

This call-back is also executed in CI runs and in all other cases where sidekiq is loaded but not used with real redis.

As a work-around, keep the at_exit hook but communicate to redis only if there is something to send, i.e. the number of processed or failed jobs is greater than zero
  • Loading branch information
Mikhail Doronin committed Mar 23, 2020
1 parent 290d4f3 commit b2b7399
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -5,6 +5,7 @@
HEAD
---------

- Fix: Do not connect to redis at ruby vm exit when not needed. [#4502]
- Remove Redis connection naming [#4479]

6.0.6
Expand Down
18 changes: 10 additions & 8 deletions lib/sidekiq/launcher.rb
Expand Up @@ -100,15 +100,17 @@ def self.flush_stats
nowdate = Time.now.utc.strftime("%Y-%m-%d")
fails = Processor::FAILURE.reset
procd = Processor::PROCESSED.reset
Sidekiq.redis do |conn|
conn.pipelined do
conn.incrby("stat:processed", procd)
conn.incrby("stat:processed:#{nowdate}", procd)
conn.expire("stat:processed:#{nowdate}", STATS_TTL)
if fails + procd > 0
Sidekiq.redis do |conn|
conn.pipelined do
conn.incrby("stat:processed", procd)
conn.incrby("stat:processed:#{nowdate}", procd)
conn.expire("stat:processed:#{nowdate}", STATS_TTL)

conn.incrby("stat:failed", fails)
conn.incrby("stat:failed:#{nowdate}", fails)
conn.expire("stat:failed:#{nowdate}", STATS_TTL)
conn.incrby("stat:failed", fails)
conn.incrby("stat:failed:#{nowdate}", fails)
conn.expire("stat:failed:#{nowdate}", STATS_TTL)
end
end
end
end
Expand Down

0 comments on commit b2b7399

Please sign in to comment.