| 1 | package Object::Remote::WatchDog; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | use Object::Remote::Logging qw (:log :dlog router); | ||||||||||||||||||||
| 4 | use Moo; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | has timeout => ( is => 'ro', required => 1 ); | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | BEGIN { router()->exclude_forwarding; } | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | sub instance { | ||||||||||||||||||||
| 11 | 0 | ▶ | my ($class, @args) = @_; | ||||||||||||||||||
|
Subroutine
instance: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | return our $WATCHDOG ||= do { | ||||||||||||||||||
|
Condition0%0/3
our $WATCHDOG ||= do {
&log_trace(sub {
"Constructing new instance of global watchdog";
}
);
$class->new(@args)
}
MC/DC0%0/2
our $WATCHDOG ||= do {
&log_trace(sub {
"Constructing new instance of global watchdog";
}
);
$class->new(@args)
}
our $WATCHDOG
do {
&log_trace(sub {
"Constructing new instance of global watchdog";
}
);
$class->new(@args)
}
Truth table0%0/3
A ||= B
A= our $WATCHDOGB= do {
&log_trace(sub {
"Constructing new instance of global watchdog";
}
);
$class->new(@args)
}
| |||||||||||||||||||||
| 14 | 0 | ▶ | log_trace { "Constructing new instance of global watchdog" }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 15 | 0 | $class->new(@args); | |||||||||||||||||||
| 16 | }; | ||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | #start the watchdog | ||||||||||||||||||||
| 20 | sub BUILD { | ||||||||||||||||||||
| 21 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | $SIG{ALRM} = sub { | ||||||||||||||||||||
| 24 | #if the Watchdog is killing the process we don't want any chance of the | ||||||||||||||||||||
| 25 | #process not actually exiting and die could be caught by an eval which | ||||||||||||||||||||
| 26 | #doesn't do us any good | ||||||||||||||||||||
| 27 | 0 | ▶ | log_fatal { "Watchdog has expired, terminating the process" }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 28 | 0 | exit(1); | |||||||||||||||||||
| 29 | 0 | }; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | Dlog_debug { "Initializing watchdog with timeout of $_ seconds" } $self->timeout; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 32 | 0 | alarm($self->timeout); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | #invoke at least once per timeout to stop | ||||||||||||||||||||
| 36 | #the watchdog from killing the process | ||||||||||||||||||||
| 37 | sub reset { | ||||||||||||||||||||
| 38 | 0 | ▶ | die "Attempt to reset the watchdog before it was constructed" | ||||||||||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 39 | unless defined our $WATCHDOG; | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | log_debug { "Watchdog has been reset" }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 42 | 0 | alarm($WATCHDOG->timeout); | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | #must explicitly call this method to stop the | ||||||||||||||||||||
| 46 | #watchdog from killing the process - if the | ||||||||||||||||||||
| 47 | #watchdog is lost because it goes out of scope | ||||||||||||||||||||
| 48 | #it makes sense to still terminate the process | ||||||||||||||||||||
| 49 | sub shutdown { | ||||||||||||||||||||
| 50 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | 0 | ▶ | log_debug { "Watchdog is shutting down" }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 52 | 0 | alarm(0); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 1; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||