1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Do not connect to redis at exit if not needed (#4502)

A fix for https://github.com/mperham/sidekiq/issues/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

Co-authored-by: Mikhail Doronin <mikhail.doronin@capitainetrain.com>
This commit is contained in:
Mikhail Doronin 2020-03-23 23:11:23 +01:00 committed by GitHub
parent 290d4f35df
commit b2b8558fdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -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

View file

@ -100,15 +100,17 @@ module Sidekiq
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