class Roundhouse::Launcher
The Launcher
is a very simple Actor
whose job is to start, monitor and stop the core Actors in Roundhouse
. If any of these actors die, the Roundhouse
process exits immediately.
Attributes
fetcher[R]
manager[R]
poller[R]
Public Class Methods
new(options)
click to toggle source
# File lib/roundhouse/launcher.rb, line 19 def initialize(options) @condvar = Celluloid::Condition.new @manager = Roundhouse::Manager.new_link(@condvar, options) @poller = Roundhouse::Scheduled::Poller.new_link @fetcher = Roundhouse::Fetcher.new_link(@manager, options) @manager.fetcher = @fetcher @done = false @options = options end
Public Instance Methods
actor_died(actor, reason)
click to toggle source
# File lib/roundhouse/launcher.rb, line 29 def actor_died(actor, reason) # https://github.com/mperham/sidekiq/issues/2057#issuecomment-66485477 return if @done || !reason Roundhouse.logger.warn("Roundhouse died due to the following error, cannot recover, process exiting") handle_exception(reason) exit(1) end
run()
click to toggle source
# File lib/roundhouse/launcher.rb, line 38 def run watchdog('Launcher#run') do manager.async.start poller.async.poll(true) start_heartbeat end end
stop()
click to toggle source
# File lib/roundhouse/launcher.rb, line 47 def stop watchdog('Launcher#stop') do logger.debug 'Stopping launcher' @done = true Roundhouse::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 Roundhouse but necessary for Roundhouse Pro. Roundhouse::Fetcher.strategy.bulk_requeue([], @options) stop_heartbeat end end
Private Instance Methods
start_heartbeat()
click to toggle source
# File lib/roundhouse/launcher.rb, line 69 def start_heartbeat key = identity data = { 'hostname' => hostname, 'started_at' => Time.now.to_f, 'pid' => $$, 'tag' => @options[:tag] || '', 'concurrency' => @options[:concurrency], 'labels' => Roundhouse.options[:labels], 'identity' => identity, } # this data doesn't change so dump it to a string # now so we don't need to dump it every heartbeat. json = Roundhouse.dump_json(data) manager.heartbeat(key, data, json) end
stop_heartbeat()
click to toggle source
# File lib/roundhouse/launcher.rb, line 86 def stop_heartbeat Roundhouse.redis do |conn| conn.pipelined do conn.srem('processes', identity) conn.del("#{identity}:workers") end end rescue # best effort, ignore network errors end