Class: Sidekiq::Launcher
- Inherits:
-
Object
- Object
- Sidekiq::Launcher
- Defined in:
- lib/sidekiq/launcher.rb
Overview
The Launcher is a very simple Actor whose job is to start, monitor and stop the core Actors in Sidekiq. If any of these actors die, the Sidekiq process exits immediately.
Constant Summary
Constants included from Util
Instance Attribute Summary collapse
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#poller ⇒ Object
readonly
Returns the value of attribute poller.
Instance Method Summary collapse
- #actor_died(actor, reason) ⇒ Object
-
#initialize(options) ⇒ Launcher
constructor
A new instance of Launcher.
- #run ⇒ Object
- #stop ⇒ Object
Methods included from Util
#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #want_a_hertz_donut?, #watchdog
Methods included from ExceptionHandler
Methods included from Actor
Constructor Details
#initialize(options) ⇒ Launcher
Returns a new instance of Launcher.
19 20 21 22 23 24 25 26 27 |
# File 'lib/sidekiq/launcher.rb', line 19 def initialize() @condvar = Celluloid::Condition.new @manager = Sidekiq::Manager.new_link(@condvar, ) @poller = Sidekiq::Scheduled::Poller.new_link @fetcher = Sidekiq::Fetcher.new_link(@manager, ) @manager.fetcher = @fetcher @done = false @options = end |
Instance Attribute Details
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
17 18 19 |
# File 'lib/sidekiq/launcher.rb', line 17 def fetcher @fetcher end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
17 18 19 |
# File 'lib/sidekiq/launcher.rb', line 17 def manager @manager end |
#poller ⇒ Object (readonly)
Returns the value of attribute poller.
17 18 19 |
# File 'lib/sidekiq/launcher.rb', line 17 def poller @poller end |
Instance Method Details
#actor_died(actor, reason) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/sidekiq/launcher.rb', line 29 def actor_died(actor, reason) # https://github.com/mperham/sidekiq/issues/2057#issuecomment-66485477 return if @done || !reason Sidekiq.logger.warn("Sidekiq died due to the following error, cannot recover, process exiting") handle_exception(reason) exit(1) end |
#run ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/sidekiq/launcher.rb', line 38 def run watchdog('Launcher#run') do manager.async.start poller.async.poll(true) start_heartbeat end end |
#stop ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sidekiq/launcher.rb', line 47 def stop watchdog('Launcher#stop') do @done = true Sidekiq::Fetcher.done! fetcher.terminate if fetcher.alive? poller.terminate if poller.alive? manager.async.stop(:shutdown => true, :timeout => @options[:timeout]) @condvar.wait manager.terminate # Requeue everything in case there was a worker who grabbed work while stopped # This call is a no-op in Sidekiq but necessary for Sidekiq Pro. Sidekiq::Fetcher.strategy.bulk_requeue([], @options) stop_heartbeat end end |