Class: ChildProcess::AbstractProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/childprocess/abstract_process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ AbstractProcess

Returns a new instance of AbstractProcess.



5
6
7
8
9
# File 'lib/childprocess/abstract_process.rb', line 5

def initialize(args)
  @args      = args
  @started   = false
  @exit_code = nil
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



3
4
5
# File 'lib/childprocess/abstract_process.rb', line 3

def exit_code
  @exit_code
end

Instance Method Details

#alive?Boolean

Is this process running?

Returns:

  • (Boolean)


48
49
50
# File 'lib/childprocess/abstract_process.rb', line 48

def alive?
  started? && !exited?
end

#crashed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/childprocess/abstract_process.rb', line 52

def crashed?
  @exit_code && @exit_code != 0
end

#exited?Boolean

Did the process exit?

Returns:

  • (Boolean)

Raises:



40
41
42
# File 'lib/childprocess/abstract_process.rb', line 40

def exited?
  raise SubclassResponsibility, "exited?"
end

#poll_for_exit(timeout) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/childprocess/abstract_process.rb', line 56

def poll_for_exit(timeout)
  log "polling #{timeout} seconds for exit"

  end_time = Time.now + timeout
  until (ok = exited?) || Time.now > end_time
    sleep POLL_INTERVAL
  end

  unless ok
    raise TimeoutError, "process still alive after #{timeout} seconds"
  end
end

#startAbstractProcess

Launch the child process

Returns:



17
18
19
20
21
22
# File 'lib/childprocess/abstract_process.rb', line 17

def start
  launch_process
  @started = true

  self
end

#stop(timeout = 3) ⇒ Object

Forcibly terminate the process, using increasingly harsher methods if possible.

Parameters:

  • timeout (Fixnum) (defaults to: 3)

    (3) Seconds to wait before trying the next method.

Raises:



30
31
32
# File 'lib/childprocess/abstract_process.rb', line 30

def stop(timeout = 3)
  raise SubclassResponsibility, "stop"
end