Class: Explorer::Process
- Inherits:
-
Object
- Object
- Explorer::Process
- Includes:
- Celluloid::IO
- Defined in:
- lib/explorer/process.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#log_watcher ⇒ Object
readonly
Returns the value of attribute log_watcher.
-
#pgid ⇒ Object
readonly
Returns the value of attribute pgid.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#working_dir ⇒ Object
readonly
Returns the value of attribute working_dir.
Instance Method Summary collapse
-
#initialize(label, command, working_dir: ENV['PWD'], log_watcher: nil, env: {}) ⇒ Process
constructor
Log watcher should implement a ‘log’ method which accepts a label and a line of text Log watcher should also be thread-safe or an actor.
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop(sig = 'INT') ⇒ Object
- #stopped? ⇒ Boolean
- #wait_on_stop ⇒ Object
Constructor Details
#initialize(label, command, working_dir: ENV['PWD'], log_watcher: nil, env: {}) ⇒ Process
Log watcher should implement a ‘log’ method which accepts a label and a line of text Log watcher should also be thread-safe or an actor
12 13 14 15 16 17 18 19 20 |
# File 'lib/explorer/process.rb', line 12 def initialize(label, command, working_dir: ENV['PWD'], log_watcher: nil, env: {}) @label = label @command = command @working_dir = File.(working_dir) @log_watcher = log_watcher @env = env @state = :stopped @status = nil end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/explorer/process.rb', line 7 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
8 9 10 |
# File 'lib/explorer/process.rb', line 8 def env @env end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/explorer/process.rb', line 7 def label @label end |
#log_watcher ⇒ Object (readonly)
Returns the value of attribute log_watcher.
8 9 10 |
# File 'lib/explorer/process.rb', line 8 def log_watcher @log_watcher end |
#pgid ⇒ Object (readonly)
Returns the value of attribute pgid.
8 9 10 |
# File 'lib/explorer/process.rb', line 8 def pgid @pgid end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
8 9 10 |
# File 'lib/explorer/process.rb', line 8 def pid @pid end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
8 9 10 |
# File 'lib/explorer/process.rb', line 8 def pipe @pipe end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/explorer/process.rb', line 7 def state @state end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/explorer/process.rb', line 7 def status @status end |
#working_dir ⇒ Object (readonly)
Returns the value of attribute working_dir.
7 8 9 |
# File 'lib/explorer/process.rb', line 7 def working_dir @working_dir end |
Instance Method Details
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/explorer/process.rb', line 30 def start return Actor.current if @state == :started @status = nil @pipe, slave = PTY.open slave.raw! @pid = spawn_process(label, command, working_dir: working_dir, pipe: slave) @pgid = ::Process.getpgid(@pid) slave.close @state = :started signal :state_changed wait_pid async.read_pipe return Actor.current end |
#started? ⇒ Boolean
22 23 24 |
# File 'lib/explorer/process.rb', line 22 def started? @state == :started end |
#stop(sig = 'INT') ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/explorer/process.rb', line 49 def stop(sig='INT') return Actor.current if @state == :stopped begin ::Process.kill(sig, -pgid) wait_on_stop rescue end return Actor.current end |
#stopped? ⇒ Boolean
26 27 28 |
# File 'lib/explorer/process.rb', line 26 def stopped? @state == :stopped end |
#wait_on_stop ⇒ Object
59 60 61 62 63 64 |
# File 'lib/explorer/process.rb', line 59 def wait_on_stop while @state != :stopped wait :state_changed end return Actor.current end |