1 package Object::Remote::WatchDog;
3 use Object::Remote::MiniLoop;
4 use Object::Remote::Logging qw (:log :dlog router);
7 has timeout => ( is => 'ro', required => 1 );
9 BEGIN { router()->exclude_forwarding; }
12 my ($orig, $self, @args) = @_;
15 return $WATCHDOG if defined $WATCHDOG;
16 log_trace { "Constructing new instance of global watchdog" };
17 return $WATCHDOG = $self->$orig(@args);
25 #if the Watchdog is killing the process we don't want any chance of the
26 #process not actually exiting and die could be caught by an eval which
27 #doesn't do us any good
28 log_fatal { "Watchdog has expired, terminating the process" };
32 Dlog_debug { "Initializing watchdog with timeout of $_ seconds" } $self->timeout;
33 alarm($self->timeout);
36 #invoke at least once per timeout to stop
37 #the watchdog from killing the process
40 die "Attempt to reset the watchdog before it was constructed"
41 unless defined $WATCHDOG;
43 log_debug { "Watchdog has been reset" };
44 alarm($WATCHDOG->timeout);
47 #must explicitly call this method to stop the
48 #watchdog from killing the process - if the
49 #watchdog is lost because it goes out of scope
50 #it makes sense to still terminate the process
53 log_debug { "Watchdog is shutting down" };