fix worker restart to happen once per hour per day

This commit is contained in:
Oliver Gorwits
2014-11-14 21:44:48 +00:00
parent db9775780b
commit 445d26bb31
2 changed files with 5 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
2.029013_001 - 2014-11-13
2.029013_002 - 2014-11-14
[ENHANCEMENTS]

View File

@@ -10,6 +10,8 @@ use namespace::clean;
use App::Netdisco::JobQueue qw/jq_defer jq_complete/;
sub worker_begin { (shift)->{started} = time }
sub worker_body {
my $self = shift;
my $wid = $self->wid;
@@ -42,7 +44,8 @@ sub worker_body {
# restart worker once a day.
# relies on the worker seeing a job at least every hour.
my $hour = [localtime()]->[2];
if ($wid and (($wid % 24) == $hour)) {
if ($wid and (time >= ($self->{started} + 86400))
and ($hour == ($wid % 24))) {
$self->exit(0, "recycling worker $wid");
}
}