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, #redis, #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
# File 'lib/sidekiq/launcher.rb', line 19

def initialize(options)
  @manager = Sidekiq::Manager.new_link 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



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

#runObject



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

#stopObject



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