class Subserver::Launcher

The Launcher is a very simple Actor whose job is to start, monitor and stop the core Actors in Subserver. If any of these actors die, the Subserver process exits immediately.

Attributes

manager[RW]

Public Class Methods

new(options) click to toggle source
# File lib/subserver/launcher.rb, line 14
def initialize(options)
  @manager = Subserver::Manager.new(options)
  @done = false
  @options = options
end

Public Instance Methods

quiet() click to toggle source

Stops this instance from processing any more jobs,

# File lib/subserver/launcher.rb, line 26
def quiet
  @done = true
  @manager.quiet
end
run() click to toggle source
# File lib/subserver/launcher.rb, line 20
def run
  @manager.start
end
stop() click to toggle source

Shuts down the process. This method does not return until all work is complete and cleaned up. It can take up to the timeout to complete.

# File lib/subserver/launcher.rb, line 34
def stop
  deadline = Time.now + @options[:timeout]

  @done = true
  @manager.quiet
  @manager.stop(deadline)
end
stopping?() click to toggle source
# File lib/subserver/launcher.rb, line 42
def stopping?
  @done
end

Private Instance Methods

to_data() click to toggle source
# File lib/subserver/launcher.rb, line 48
def to_data
  @data ||= begin
    {
      'hostname' => hostname,
      'started_at' => Time.now.to_f,
      'pid' => $$,
      'tag' => @options[:tag] || '',
      'queues' => @options[:queues].uniq,
      'labels' => @options[:labels],
      'identity' => identity,
    }
  end
end
to_json() click to toggle source
# File lib/subserver/launcher.rb, line 62
def to_json
  @json ||= begin
    # this data changes infrequently so dump it to a string
    # now so we don't need to dump it every heartbeat.
    Subserver.dump_json(to_data)
  end
end