Class: Subserver::Launcher

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/subserver/launcher.rb

Overview

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.

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, #safe_thread, #watchdog

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initialize(options) ⇒ Launcher

Returns a new instance of Launcher.



14
15
16
17
18
# File 'lib/subserver/launcher.rb', line 14

def initialize(options)
  @manager = Subserver::Manager.new(options)
  @done = false
  @options = options
end

Instance Attribute Details

#managerObject

Returns the value of attribute manager.



12
13
14
# File 'lib/subserver/launcher.rb', line 12

def manager
  @manager
end

Instance Method Details

#quietObject

Stops this instance from processing any more jobs,



26
27
28
29
# File 'lib/subserver/launcher.rb', line 26

def quiet
  @done = true
  @manager.quiet
end

#runObject



20
21
22
# File 'lib/subserver/launcher.rb', line 20

def run
  @manager.start
end

#stopObject

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.



34
35
36
37
38
39
40
# File 'lib/subserver/launcher.rb', line 34

def stop
  deadline = Time.now + @options[:timeout]

  @done = true
  @manager.quiet
  @manager.stop(deadline)
end

#stopping?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/subserver/launcher.rb', line 42

def stopping?
  @done
end

#to_dataObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# 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_jsonObject



62
63
64
65
66
67
68
# 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