Class: PidWatcher
- Inherits:
-
Object
- Object
- PidWatcher
- Defined in:
- lib/pid_watcher.rb
Constant Summary collapse
- VERSION =
"0.0.2"- DEFAULT_TIMEOUT =
10 * 60
- DEFAULT_MESSAGE =
"Process %{pid} finished"- TIMEOUT_MESSAGE =
"Timeout for process %{pid}"- TITLE =
'Pid Watcher'
Instance Method Summary collapse
-
#initialize(pid, options) ⇒ PidWatcher
constructor
A new instance of PidWatcher.
- #watch ⇒ Object
Constructor Details
#initialize(pid, options) ⇒ PidWatcher
Returns a new instance of PidWatcher.
11 12 13 14 15 16 |
# File 'lib/pid_watcher.rb', line 11 def initialize(pid, ) @pid = pid @message = [:message] || DEFAULT_MESSAGE @timeout = [:timeout] || DEFAULT_TIMEOUT @command = [:command] end |
Instance Method Details
#watch ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pid_watcher.rb', line 18 def watch Process.daemon Timeout::timeout(timeout) do while pid_exists? sleep(1) end run_command unless command.nil? finish_notify end rescue Timeout::Error timeout_notify end |