summaryrefslogtreecommitdiffstats
path: root/Bugzilla/JobQueue.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-03-13 15:37:03 +0100
committerGitHub <noreply@github.com>2018-03-13 15:37:03 +0100
commit6b8fa6c161e88a9054cdcef49aa76aa857ed9a72 (patch)
treefd5e28edc46ae33ef07733357a011aa29e6ace75 /Bugzilla/JobQueue.pm
parent294b3090c1eac02ed1d561ddb797814bd3537bfb (diff)
downloadbugzilla-6b8fa6c161e88a9054cdcef49aa76aa857ed9a72.tar.gz
bugzilla-6b8fa6c161e88a9054cdcef49aa76aa857ed9a72.tar.xz
Bug 1441181 - Step 4 - Re-implement subprocess code with IO::Async
Diffstat (limited to 'Bugzilla/JobQueue.pm')
-rw-r--r--Bugzilla/JobQueue.pm21
1 files changed, 21 insertions, 0 deletions
diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm
index 55d40bfb8..e3cf9733f 100644
--- a/Bugzilla/JobQueue.pm
+++ b/Bugzilla/JobQueue.pm
@@ -14,6 +14,10 @@ use warnings;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Install::Util qw(install_string);
+use Bugzilla::DaemonControl qw(catch_signal);
+use IO::Async::Timer::Periodic;
+use IO::Async::Loop;
+use Future;
use base qw(TheSchwartz);
# This maps job names for Bugzilla::JobQueue to the appropriate modules.
@@ -91,6 +95,23 @@ sub insert {
return $retval;
}
+sub work {
+ my ($self, $delay) = @_;
+ $delay ||= 5;
+ my $loop = IO::Async::Loop->new;
+ my $timer = IO::Async::Timer::Periodic->new(
+ first_interval => 0,
+ interval => $delay,
+ reschedule => 'drift',
+ on_tick => sub { $self->work_once }
+ );
+ $loop->add($timer);
+ $timer->start;
+ Future->wait_any(map { catch_signal($_) } qw( INT TERM HUP ))->get;
+ $timer->stop;
+ $loop->remove($timer);
+}
+
# Clear the request cache at the start of each run.
sub work_once {
my $self = shift;