Class: Magistrate::Supervisor
- Inherits:
-
Object
- Object
- Magistrate::Supervisor
- Defined in:
- lib/magistrate/supervisor.rb
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #list(params = nil) ⇒ Object
- #run(params = nil) ⇒ Object
- #start(params = nil) ⇒ Object
-
#status ⇒ Object
Returns the actual hash of all workers and their status.
- #stop(params = nil) ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Supervisor
Returns a new instance of Supervisor.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/magistrate/supervisor.rb', line 13 def initialize(config_file) @workers = {} #File.expand_path('~') @pid_path = File.join( 'tmp', 'pids' ) FileUtils.mkdir_p(@pid_path) unless File.directory? @pid_path @config = File.open(config_file) { |file| YAML.load(file) } @config.recursive_symbolize_keys! @uri = URI.parse @config[:monitor_url] @config[:workers].each do |k,v| @workers[k] = Process.new(k,v) end @loaded_from = nil end |
Instance Method Details
#list(params = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/magistrate/supervisor.rb', line 62 def list(params = nil) set_target_states! require 'pp' pp status end |
#run(params = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/magistrate/supervisor.rb', line 33 def run(params = nil) puts "Starting Magistrate [[[#{self.name}]]] talking to [[[#{@config[:monitor_url]}]]]" set_target_states! # Pull in all already-running workers and set their target states @workers.each do |k, worker| worker.supervise! end send_status end |
#start(params = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/magistrate/supervisor.rb', line 46 def start(params = nil) worker = params puts "Starting: #{worker}" @workers[worker.to_sym].supervise! # Save that we've requested this to be started end |
#status ⇒ Object
Returns the actual hash of all workers and their status
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/magistrate/supervisor.rb', line 70 def status s = {} @workers.each do |k,process| s[k] = { :state => process.state, :target_state => process.target_state } end s end |
#stop(params = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/magistrate/supervisor.rb', line 54 def stop(params = nil) worker = params puts "Stopping: #{worker}" @workers[worker.to_sym].stop # Save that we've requested this to be stopped end |