Class: Sidekiq::Launcher
- Inherits:
-
Object
- Object
- Sidekiq::Launcher
- Includes:
- Component
- Defined in:
- lib/sidekiq/launcher.rb
Overview
The Launcher starts the Capsule Managers, the Poller thread and provides the process heartbeat.
Constant Summary collapse
- STATS_TTL =
5 years
5 * 365 * 24 * 60 * 60
- PROCTITLES =
[ proc { "sidekiq" }, proc { Sidekiq::VERSION }, proc { |me, data| data["tag"] }, proc { |me, data| "[#{Processor::WORK_STATE.size} of #{me.config.total_concurrency} busy]" }, proc { |me, data| "stopping" if me.stopping? } ]
Instance Attribute Summary collapse
-
#managers ⇒ Object
Returns the value of attribute managers.
-
#poller ⇒ Object
Returns the value of attribute poller.
Attributes included from Component
Instance Method Summary collapse
-
#heartbeat ⇒ Object
If embedding Sidekiq, you can have the process heartbeat call this method to regularly heartbeat rather than creating a separate thread.
-
#initialize(config, embedded: false) ⇒ Launcher
constructor
A new instance of Launcher.
-
#quiet ⇒ Object
Stops this instance from processing any more jobs,.
-
#run(async_beat: true) ⇒ Object
Start this Sidekiq instance.
-
#stop ⇒ Object
Shuts down this Sidekiq instance.
- #stopping? ⇒ Boolean
Methods included from Component
#default_tag, #fire_event, #handle_exception, #hostname, #identity, #inspect, #logger, #mono_ms, #process_nonce, #real_ms, #redis, #safe_thread, #tid, #watchdog
Constructor Details
#initialize(config, embedded: false) ⇒ Launcher
Returns a new instance of Launcher.
25 26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq/launcher.rb', line 25 def initialize(config, embedded: false) @config = config @embedded = @managers = config.capsules.values.map do |cap| Sidekiq::Manager.new(cap) end @poller = Sidekiq::Scheduled::Poller.new(@config) @done = false end |
Instance Attribute Details
#managers ⇒ Object
Returns the value of attribute managers.
23 24 25 |
# File 'lib/sidekiq/launcher.rb', line 23 def managers @managers end |
#poller ⇒ Object
Returns the value of attribute poller.
23 24 25 |
# File 'lib/sidekiq/launcher.rb', line 23 def poller @poller end |
Instance Method Details
#heartbeat ⇒ Object
If embedding Sidekiq, you can have the process heartbeat call this method to regularly heartbeat rather than creating a separate thread.
81 82 83 |
# File 'lib/sidekiq/launcher.rb', line 81 def heartbeat ❤ end |
#quiet ⇒ Object
Stops this instance from processing any more jobs,
47 48 49 50 51 52 53 54 |
# File 'lib/sidekiq/launcher.rb', line 47 def quiet return if @done @done = true @managers.each(&:quiet) @poller.terminate fire_event(:quiet, reverse: true) end |
#run(async_beat: true) ⇒ Object
Start this Sidekiq instance. If an embedding process already has a heartbeat thread, caller can use ‘async_beat: false` and instead have thread call Launcher#heartbeat every N seconds.
38 39 40 41 42 43 44 |
# File 'lib/sidekiq/launcher.rb', line 38 def run(async_beat: true) logger.debug { @config.merge!({}) } Sidekiq.freeze! @thread = safe_thread("heartbeat", &method(:start_heartbeat)) if async_beat @poller.start @managers.each(&:start) end |
#stop ⇒ Object
Shuts down this Sidekiq instance. Waits up to the deadline for all jobs to complete.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sidekiq/launcher.rb', line 57 def stop deadline = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) + @config[:timeout] quiet stoppers = @managers.map do |mgr| Thread.new do mgr.stop(deadline) end end fire_event(:shutdown, reverse: true) stoppers.each(&:join) clear_heartbeat fire_event(:exit, reverse: true) end |
#stopping? ⇒ Boolean
74 75 76 |
# File 'lib/sidekiq/launcher.rb', line 74 def stopping? @done end |