Class: PidWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pid_watcher.rb,
lib/pid_watcher/version.rb

Constant Summary collapse

VERSION =
"0.0.1"
DEFAULT_TIMEOUT =
10 * 60
DEFAULT_MESSAGE =
"Process %{pid} finished"
TIMEOUT_MESSAGE =
"Timeout for process %{pid}"
TITLE =
'Pid Watcher'

Instance Method Summary collapse

Constructor Details

#initialize(pid, message = nil, timeout = nil) ⇒ PidWatcher

Returns a new instance of PidWatcher.



11
12
13
14
15
# File 'lib/pid_watcher.rb', line 11

def initialize(pid, message = nil, timeout = nil)
  @pid     = pid
  @message = message || DEFAULT_MESSAGE
  @timeout = timeout || DEFAULT_TIMEOUT
end

Instance Method Details

#watchObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pid_watcher.rb', line 17

def watch
  Process.daemon(nil, true)

  Timeout::timeout(timeout) do
    while pid_exists?
      sleep(1)
    end
    finish_notify
  end
rescue Timeout::Error
  timeout_notify
end