Class: Sidekiq::Launcher

Inherits:
Object
  • Object
show all
Includes:
Actor, Util
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

Util::EXPIRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #want_a_hertz_donut?, #watchdog

Methods included from ExceptionHandler

#handle_exception

Methods included from Actor

included

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(options)
  @condvar = Celluloid::Condition.new
  @manager = Sidekiq::Manager.new_link(@condvar, options)
  @poller = Sidekiq::Scheduled::Poller.new_link
  @fetcher = Sidekiq::Fetcher.new_link(@manager, options)
  @manager.fetcher = @fetcher
  @done = false
  @options = options
end

Instance Attribute Details

#fetcherObject (readonly)

Returns the value of attribute fetcher.



17
18
19
# File 'lib/sidekiq/launcher.rb', line 17

def fetcher
  @fetcher
end

#managerObject (readonly)

Returns the value of attribute manager.



17
18
19
# File 'lib/sidekiq/launcher.rb', line 17

def manager
  @manager
end

#pollerObject (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

#runObject



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

#stopObject



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