Skip to content

Commit

Permalink
Refactor #4502 a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Mar 26, 2020
1 parent 2504d0b commit 0b44ca1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes.md
Expand Up @@ -5,8 +5,8 @@
HEAD
---------

- Fix: Do not connect to redis at ruby vm exit when not needed. [#4502]
- Refactor systemd integration to work better with custom binaries [#4511]
- Don't connect to Redis at process exit if not needed [#4502]
- Remove Redis connection naming [#4479]

6.0.6
Expand Down
12 changes: 9 additions & 3 deletions lib/sidekiq/launcher.rb
Expand Up @@ -97,10 +97,12 @@ def heartbeat
end

def self.flush_stats
nowdate = Time.now.utc.strftime("%Y-%m-%d")
fails = Processor::FAILURE.reset
procd = Processor::PROCESSED.reset
if fails + procd > 0
return if fails + procd == 0

nowdate = Time.now.utc.strftime("%Y-%m-%d")
begin
Sidekiq.redis do |conn|
conn.pipelined do
conn.incrby("stat:processed", procd)
Expand All @@ -112,6 +114,10 @@ def self.flush_stats
conn.expire("stat:failed:#{nowdate}", STATS_TTL)
end
end
rescue => ex
# we're exiting the process, things might be shut down so don't
# try to handle the exception
Sidekiq.logger.warn("Unable to flush stats: #{ex}")
end
end
at_exit(&method(:flush_stats))
Expand Down Expand Up @@ -166,7 +172,7 @@ def ❤
::Process.kill(msg, ::Process.pid)
rescue => e
# ignore all redis/network issues
logger.error("heartbeat: #{e.message}")
logger.error("heartbeat: #{e}")
# don't lose the counts if there was a network issue
Processor::PROCESSED.incr(procd)
Processor::FAILURE.incr(fails)
Expand Down

0 comments on commit 0b44ca1

Please sign in to comment.