add notification system
[god.git] / lib / god / conditions / process_exits.rb
blob95210fdda072a478d04cd7a26800f30781d1039b
1 module God
2   module Conditions
3     
4     class ProcessExits < EventCondition
5       def valid?
6         valid = true
7         valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
8         valid
9       end
10     
11       def register
12         pid = File.read(self.watch.pid_file).strip.to_i
13         
14         begin
15           EventHandler.register(pid, :proc_exit) do
16             Hub.trigger(self)
17           end
18         rescue StandardError
19           raise EventRegistrationFailedError.new
20         end
21       end
22       
23       def deregister
24         pid = File.read(self.watch.pid_file).strip.to_i
25         EventHandler.deregister(pid, :proc_exit)
26       end
27     end
28     
29   end
30 end