mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Exceptions raised during the startup event should kill the process, fixes #3717
This commit is contained in:
parent
89fcf0c145
commit
b9d4eae062
4 changed files with 16 additions and 13 deletions
|
@ -89,7 +89,7 @@ module Sidekiq
|
|||
|
||||
# Before this point, the process is initializing with just the main thread.
|
||||
# Starting here the process will now have multiple threads running.
|
||||
fire_event(:startup)
|
||||
fire_event(:startup, reverse: false, reraise: true)
|
||||
|
||||
logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join(', ')}" }
|
||||
logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(', ')}" }
|
||||
|
|
|
@ -54,7 +54,7 @@ module Sidekiq
|
|||
|
||||
logger.info { "Terminating quiet workers" }
|
||||
@workers.each { |x| x.terminate }
|
||||
fire_event(:quiet, true)
|
||||
fire_event(:quiet, reverse: true)
|
||||
end
|
||||
|
||||
# hack for quicker development / testing environment #2774
|
||||
|
@ -62,7 +62,7 @@ module Sidekiq
|
|||
|
||||
def stop(deadline)
|
||||
quiet
|
||||
fire_event(:shutdown, true)
|
||||
fire_event(:shutdown, reverse: true)
|
||||
|
||||
# some of the shutdown events can be async,
|
||||
# we don't have any way to know when they're done but
|
||||
|
|
|
@ -50,7 +50,10 @@ module Sidekiq
|
|||
@@identity ||= "#{hostname}:#{$$}:#{process_nonce}"
|
||||
end
|
||||
|
||||
def fire_event(event, reverse=false)
|
||||
def fire_event(event, options={})
|
||||
reverse = options[:reverse]
|
||||
reraise = options[:reraise]
|
||||
|
||||
arr = Sidekiq.options[:lifecycle_events][event]
|
||||
arr.reverse! if reverse
|
||||
arr.each do |block|
|
||||
|
@ -58,6 +61,7 @@ module Sidekiq
|
|||
block.call
|
||||
rescue => ex
|
||||
handle_exception(ex, { context: "Exception during Sidekiq lifecycle event.", event: event })
|
||||
raise ex if reraise
|
||||
end
|
||||
end
|
||||
arr.clear
|
||||
|
|
|
@ -7,15 +7,14 @@ class TestUtil < Sidekiq::Test
|
|||
include Sidekiq::Util
|
||||
end
|
||||
|
||||
def test_tid
|
||||
x = Sidekiq::Util.tid
|
||||
y = nil
|
||||
t = Thread.new do
|
||||
Sidekiq::Util.tid
|
||||
def test_event_firing
|
||||
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }]
|
||||
h = Helpers.new
|
||||
h.fire_event(:startup)
|
||||
|
||||
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }]
|
||||
assert_raises RuntimeError do
|
||||
h.fire_event(:startup, reraise: true)
|
||||
end
|
||||
y = t.value
|
||||
assert x
|
||||
assert y
|
||||
refute_equal x, y
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue