1 package Object::Remote::WatchDog;
3 use Object::Remote::MiniLoop;
4 use Object::Remote::Logging qw ( :log :dlog );
9 #if the Watchdog is killing the process we don't want any chance of the
10 #process not actually exiting and die could be caught by an eval which
11 #doesn't do us any good
12 log_error { sprintf("Watchdog has expired, terminating the process at file %s line %s", __FILE__, __LINE__ + 1); };
17 has timeout => ( is => 'ro', required => 1 );
20 my ($orig, $self, @args) = @_;
23 return $WATCHDOG if defined $WATCHDOG;
24 log_trace { "Constructing new instance of global watchdog" };
25 return $WATCHDOG = $self->$orig(@args);
31 Dlog_debug { "Initializing watchdog with timeout of $_ seconds" } $self->timeout;
32 alarm($self->timeout);
35 #invoke at least once per timeout to stop
36 #the watchdog from killing the process
39 die "Attempt to reset the watchdog before it was constructed"
40 unless defined $WATCHDOG;
42 log_trace { "Watchdog has been reset" };
43 alarm($WATCHDOG->timeout);
46 #must explicitly call this method to stop the
47 #watchdog from killing the process - if the
48 #watchdog is lost because it goes out of scope
49 #it makes sense to still terminate the process