Class: RubySupervisor::ProcessProxy

Inherits:
NamedProxy show all
Includes:
ProcessLogsAPI
Defined in:
lib/ruby-supervisor/api/process.rb

Overview

Process Proxy.

Note: you can address programs in a group via this name: <group>:<process>

Constant Summary collapse

STATE_TO_STR =
{
     0 => :stopped,
    10 => :starting,
    20 => :running,
    30 => :backoff,
    40 => :stopping,
   100 => :exited,
   200 => :fatal,
  1000 => :unknown
}.freeze
STR_TO_STATE =
STATE_TO_STR.invert.freeze

Instance Attribute Summary

Attributes inherited from NamedProxy

#name

Instance Method Summary collapse

Methods included from ProcessLogsAPI

#logs

Methods inherited from NamedProxy

#initialize

Methods inherited from Proxy

#initialize

Constructor Details

This class inherits a constructor from RubySupervisor::NamedProxy

Instance Method Details

#infosHash

Return informations about process.

Returns:

  • (Hash)

    Informations about the process



50
51
52
# File 'lib/ruby-supervisor/api/process.rb', line 50

def infos
  request('getProcessInfo', @name)
end

#restart(wait = true, &block) ⇒ Object

Restart the process. If you pass a block to this method it will get called after the actual restart. Be aware that wehn using a block with wait = false your block will be scheduled in a separate thread !

Parameters:

  • wait (Boolean) (defaults to: true)

    if true the call will block until the process is restarted.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ruby-supervisor/api/process.rb', line 84

def restart(wait = true, &block)
  if wait
    begin
      stop(true)
    ensure
      start(true)
    end
    
    block.call if block
  else
    Thread.new do
      stop(true)
      start(true)
      block.call if block
    end
  end
end

#send_stdin(data) ⇒ Object

Write data to the process standard input.

Parameters:

  • data (String)

    data to send to the process.



108
109
110
# File 'lib/ruby-supervisor/api/process.rb', line 108

def send_stdin(data)
  request('sendProcessStdin', @name, data)
end

#start(wait = true) ⇒ Object

Start the process.

Parameters:

  • wait (Boolean) (defaults to: true)

    if true the call will block until the process is started.



60
61
62
# File 'lib/ruby-supervisor/api/process.rb', line 60

def start(wait = true)
  request('startProcess', @name, wait)
end

#stateSymbol

Return process state as symbol.

Returns:

  • (Symbol)

    The process state



40
41
42
43
# File 'lib/ruby-supervisor/api/process.rb', line 40

def state
  state = infos['state']
  STATE_TO_STR[ state ]
end

#stop(wait = true) ⇒ Object

Stop the process.

Parameters:

  • wait (Boolean) (defaults to: true)

    if true the call will block until the process is stopped.



70
71
72
# File 'lib/ruby-supervisor/api/process.rb', line 70

def stop(wait = true)
  request('stopProcess', @name, wait)
end