X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FWatchDog.pm;h=6623e02e26e306c650640b1aeb2754f51045da21;hp=2a3fc6160e82ac089339c6e4227a270f2de030e7;hb=867e4de52669f99e6478ab39afd9be27f27e04dd;hpb=c824fdf36c659b3b6dbafe23a3021f2b1d6eeb3f diff --git a/lib/Object/Remote/WatchDog.pm b/lib/Object/Remote/WatchDog.pm index 2a3fc61..6623e02 100644 --- a/lib/Object/Remote/WatchDog.pm +++ b/lib/Object/Remote/WatchDog.pm @@ -1,33 +1,34 @@ package Object::Remote::WatchDog; use Object::Remote::MiniLoop; -use Object::Remote::Logging qw ( :log :dlog ); +use Object::Remote::Logging qw (:log :dlog router); use Moo; -BEGIN { - $SIG{ALRM} = sub { - #if the Watchdog is killing the process we don't want any chance of the - #process not actually exiting and die could be caught by an eval which - #doesn't do us any good - log_error { sprintf("Watchdog has expired, terminating the process at file %s line %s", __FILE__, __LINE__ + 1); }; - exit(1); - }; -}; - has timeout => ( is => 'ro', required => 1 ); +BEGIN { router()->exclude_forwarding; } + around new => sub { my ($orig, $self, @args) = @_; our ($WATCHDOG); return $WATCHDOG if defined $WATCHDOG; log_trace { "Constructing new instance of global watchdog" }; - return $WATCHDOG = $self->$orig(@args); + return $WATCHDOG = $self->$orig(@args); }; #start the watchdog sub BUILD { my ($self) = @_; + + $SIG{ALRM} = sub { + #if the Watchdog is killing the process we don't want any chance of the + #process not actually exiting and die could be caught by an eval which + #doesn't do us any good + log_fatal { "Watchdog has expired, terminating the process" }; + exit(1); + }; + Dlog_debug { "Initializing watchdog with timeout of $_ seconds" } $self->timeout; alarm($self->timeout); } @@ -39,7 +40,7 @@ sub reset { die "Attempt to reset the watchdog before it was constructed" unless defined $WATCHDOG; - log_trace { "Watchdog has been reset" }; + log_debug { "Watchdog has been reset" }; alarm($WATCHDOG->timeout); } @@ -49,6 +50,7 @@ sub reset { #it makes sense to still terminate the process sub shutdown { my ($self) = @_; + log_debug { "Watchdog is shutting down" }; alarm(0); }