Class: Procodile::ControlSession
- Inherits:
-
Object
- Object
- Procodile::ControlSession
- Defined in:
- lib/procodile/control_session.rb
Instance Method Summary collapse
- #check_concurrency(options) ⇒ Object
-
#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.
7 8 9 10 |
# File 'lib/procodile/control_session.rb', line 7 def initialize(supervisor, client) @supervisor = supervisor @client = client end |
Instance Method Details
#check_concurrency(options) ⇒ Object
54 55 56 57 58 |
# File 'lib/procodile/control_session.rb', line 54 def check_concurrency() result = @supervisor.check_concurrency(:reload => ['reload']) result = result.each_with_object({}) { |(type, instances), hash| hash[type] = instances.map(&:to_hash) } "200 #{result.to_json}" end |
#receive_data(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/procodile/control_session.rb', line 12 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 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
49 50 51 52 |
# File 'lib/procodile/control_session.rb', line 49 def reload_config() @supervisor.reload_config "200" end |
#restart(options) ⇒ Object
44 45 46 47 |
# File 'lib/procodile/control_session.rb', line 44 def restart() instances = @supervisor.restart(:processes => ['processes'], :tag => ['tag']) "200 " + instances.map { |a| a.map { |i| i ? i.to_hash : nil } }.to_json end |
#start_processes(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/procodile/control_session.rb', line 27 def start_processes() if ['port_allocations'] if @supervisor.[:port_allocations] @supervisor.[:port_allocations].merge!(['port_allocations']) else @supervisor.[:port_allocations] = ['port_allocations'] end end instances = @supervisor.start_processes(['processes'], :tag => ['tag']) "200 " + instances.map(&:to_hash).to_json end |
#status(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/procodile/control_session.rb', line 61 def status() instances = {} @supervisor.processes.each do |process, process_instances| instances[process.name] = [] for instance in process_instances instances[process.name] << instance.to_hash end end processes = @supervisor.processes.keys.map(&:to_hash) result = { :version => Procodile::VERSION, :messages => @supervisor., :root => @supervisor.config.root, :app_name => @supervisor.config.app_name, :supervisor => @supervisor.to_hash, :instances => instances, :processes => processes, :environment_variables => @supervisor.config.environment_variables } "200 #{result.to_json}" end |
#stop(options) ⇒ Object
39 40 41 42 |
# File 'lib/procodile/control_session.rb', line 39 def stop() instances = @supervisor.stop(:processes => ['processes'], :stop_supervisor => ['stop_supervisor']) "200 " + instances.map(&:to_hash).to_json end |