Class: PidWatcher

Inherits:
Object
  • Object
show all
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

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, options)
  @pid     = pid
  @message = options[:message] || DEFAULT_MESSAGE
  @timeout = options[:timeout] || DEFAULT_TIMEOUT
  @command = options[:command]
end

Instance Method Details

#watchObject



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