From 6b8fa6c161e88a9054cdcef49aa76aa857ed9a72 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Tue, 13 Mar 2018 10:37:03 -0400 Subject: Bug 1441181 - Step 4 - Re-implement subprocess code with IO::Async --- Bugzilla/JobQueue.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Bugzilla/JobQueue.pm') 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; -- cgit v1.2.3-24-g4f1b