bug fixes
This commit is contained in:
@@ -28,7 +28,7 @@ my $mce = MCE->new(
|
|||||||
|
|
||||||
sub call_worker_body {
|
sub call_worker_body {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
$self->worker_body if $self->can('worker_body');
|
$self->worker_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub restart_worker {
|
sub restart_worker {
|
||||||
@@ -67,30 +67,7 @@ sub worker_factory {
|
|||||||
my $role = shift;
|
my $role = shift;
|
||||||
return sub {
|
return sub {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
with "App::Netdisco::Daemon::Worker::$role";
|
Role::Tiny->apply_roles_to_object($self, "App::Netdisco::Daemon::Worker::$role");
|
||||||
$self->worker_begin if $self->can('worker_begin');
|
$self->worker_begin if $self->can('worker_begin');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub interruptible_sleep {
|
|
||||||
my ($period) = @_;
|
|
||||||
my $hires = 0;
|
|
||||||
|
|
||||||
if ($period * 1000 != int($period * 1000)) {
|
|
||||||
$hires = 1;
|
|
||||||
require Time::HiRes;
|
|
||||||
import Time::HiRes qw(time sleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
my $t = time;
|
|
||||||
while (time - $t < $period) {
|
|
||||||
if ($hires) {
|
|
||||||
my $p = (time - $t < 1)
|
|
||||||
? time - $t
|
|
||||||
: 1;
|
|
||||||
sleep($p);
|
|
||||||
} else {
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ sub worker_body {
|
|||||||
|
|
||||||
# get all pending jobs
|
# get all pending jobs
|
||||||
my $rs = schema('netdisco')->resultset('Admin')
|
my $rs = schema('netdisco')->resultset('Admin')
|
||||||
->search({wid => 0});
|
->search({status => 'queued'});
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (my $job = $rs->next) {
|
while (my $job = $rs->next) {
|
||||||
@@ -64,7 +64,7 @@ sub worker_body {
|
|||||||
|
|
||||||
# TODO also check for stale jobs in Netdisco DB
|
# TODO also check for stale jobs in Netdisco DB
|
||||||
|
|
||||||
interruptible_sleep( setting('daemon_sleep_time') || 5 );
|
sleep( setting('daemon_sleep_time') || 5 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user