Class: Procodile::ControlSession
- Inherits:
-
Object
- Object
- Procodile::ControlSession
- Defined in:
- lib/procodile/control_session.rb
Instance Method Summary collapse
-
#initialize(supervisor, client) ⇒ ControlSession
constructor
A new instance of ControlSession.
- #receive_data(data) ⇒ Object
- #reload_config(options) ⇒ Object
- #restart(options) ⇒ Object
- #start_processes(options) ⇒ Object
- #status(options) ⇒ Object
- #stop(options) ⇒ Object
Constructor Details
#initialize(supervisor, client) ⇒ ControlSession
Returns a new instance of ControlSession.
6 7 8 9 |
# File 'lib/procodile/control_session.rb', line 6 def initialize(supervisor, client) @supervisor = supervisor @client = client end |
Instance Method Details
#receive_data(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/procodile/control_session.rb', line 11 def receive_data(data) command, = data.split(/\s+/, 2) = JSON.parse() if self.class.instance_methods(false).include?(command.to_sym) && command != 'receive_data' begin Procodile.log nil, 'control', "Received #{command} command" public_send(command, ) rescue Procodile::Error => e Procodile.log nil, 'control', "Error: #{e.}".color(31) "500 #{e.}" end else "404 Invaid command" end end |
#reload_config(options) ⇒ Object
42 43 44 45 |
# File 'lib/procodile/control_session.rb', line 42 def reload_config() @supervisor.reload_config "200" end |
#restart(options) ⇒ Object
37 38 39 40 |
# File 'lib/procodile/control_session.rb', line 37 def restart() instances = @supervisor.restart(:processes => ['processes']) "200 " + instances.map(&:to_hash).to_json end |
#start_processes(options) ⇒ Object
27 28 29 30 |
# File 'lib/procodile/control_session.rb', line 27 def start_processes() instances = @supervisor.start_processes(['processes']) "200 " + instances.map(&:to_hash).to_json end |
#status(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/procodile/control_session.rb', line 47 def status() instances = {} @supervisor.processes.each do |process, process_instances| instances[process.name] = [] for instance in process_instances instances[process.name] << { :description => instance.description, :pid => instance.pid, :running => instance.running?, :respawns => instance.respawns, :command => instance.process.command } end end processes = @supervisor.processes.keys.map(&:to_hash) result = {:instances => instances, :processes => processes} "200 #{result.to_json}" end |
#stop(options) ⇒ Object
32 33 34 35 |
# File 'lib/procodile/control_session.rb', line 32 def stop() instances = @supervisor.stop(:processes => ['processes']) "200 " + instances.map(&:to_hash).to_json end |