From 9e1bc7d6d7573464b026cd6a86d44b67eb04432b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 2 Jan 2013 12:28:56 +0000 Subject: [PATCH] bug fixes --- Netdisco/bin/netdisco-daemon | 27 ++----------------- .../lib/App/Netdisco/Daemon/Worker/Manager.pm | 4 +-- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index 2c506473..c0246a9f 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -28,7 +28,7 @@ my $mce = MCE->new( sub call_worker_body { my ($self) = @_; - $self->worker_body if $self->can('worker_body'); + $self->worker_body; } sub restart_worker { @@ -67,30 +67,7 @@ sub worker_factory { my $role = shift; return sub { 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'); }; } - -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); - } - } -} diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm index e7791a0c..1939e7b5 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm @@ -39,7 +39,7 @@ sub worker_body { # get all pending jobs my $rs = schema('netdisco')->resultset('Admin') - ->search({wid => 0}); + ->search({status => 'queued'}); while (1) { while (my $job = $rs->next) { @@ -64,7 +64,7 @@ sub worker_body { # TODO also check for stale jobs in Netdisco DB - interruptible_sleep( setting('daemon_sleep_time') || 5 ); + sleep( setting('daemon_sleep_time') || 5 ); } }