1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/util.rb
Michael DiScala ebd06ec67a Add random string to process identity.
In environments with deterministic hostnames and PIDs (i.e. Heroku), the
current system for constructing a process's identity string produces
collisions (e.g. a new process can assume the identity of one that has
died). In order to address this, we add a random string to the identity string.
Issue #2071.
2014-12-31 20:09:01 +00:00

53 lines
983 B
Ruby

require 'socket'
require 'securerandom'
require 'sidekiq/exception_handler'
require 'sidekiq/core_ext'
module Sidekiq
##
# This module is part of Sidekiq core and not intended for extensions.
#
module Util
include ExceptionHandler
EXPIRY = 60 * 60 * 24
def watchdog(last_words)
yield
rescue Exception => ex
handle_exception(ex, { context: last_words })
raise ex
end
def logger
Sidekiq.logger
end
def redis(&block)
Sidekiq.redis(&block)
end
def hostname
ENV['DYNO'] || Socket.gethostname
end
def process_nonce
@@process_nonce ||= SecureRandom.hex(6)
end
def identity
@@identity ||= "#{hostname}:#{$$}:#{process_nonce}"
end
def fire_event(event)
Sidekiq.options[:lifecycle_events][event].each do |block|
begin
block.call
rescue => ex
handle_exception(ex, { event: event })
end
end
end
end
end