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, #redis, #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 |
# File 'lib/sidekiq/launcher.rb', line 19 def initialize() @manager = Sidekiq::Manager.new_link @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
28 29 30 31 32 33 |
# File 'lib/sidekiq/launcher.rb', line 28 def actor_died(actor, reason) return if @done Sidekiq.logger.warn("Sidekiq died due to the following error, cannot recover, process exiting") handle_exception(reason) exit(1) end |
#run ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sidekiq/launcher.rb', line 35 def run watchdog('Launcher#run') do manager.async.start poller.async.poll(true) start_heartbeat end end |
#stop ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sidekiq/launcher.rb', line 44 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]) manager.wait(:shutdown) # Requeue everything in case there was a worker who grabbed work while stopped Sidekiq::Fetcher.strategy.bulk_requeue([], @options) stop_heartbeat end end |