summaryrefslogtreecommitdiffstats
path: root/Bugzilla/JobQueue.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-02-15 06:57:04 +0100
committerByron Jones <bjones@mozilla.com>2013-02-15 06:57:04 +0100
commitb6dedf486972c23b05f16a00c2be1c32e139eb1f (patch)
tree7451ee504401e8d075d32a76d9d6ad28adfe71bc /Bugzilla/JobQueue.pm
parent9986a6db7d542365f03f45246553060dcfcff388 (diff)
downloadbugzilla-b6dedf486972c23b05f16a00c2be1c32e139eb1f.tar.gz
bugzilla-b6dedf486972c23b05f16a00c2be1c32e139eb1f.tar.xz
Bug 832893: changes jobqueue.pl to spawn worker processes to deliver bugmail to avoid memory leaks
r=dkl, a=LpSolit
Diffstat (limited to 'Bugzilla/JobQueue.pm')
-rw-r--r--Bugzilla/JobQueue.pm60
1 files changed, 59 insertions, 1 deletions
diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm
index 098ee7935..9365a7d56 100644
--- a/Bugzilla/JobQueue.pm
+++ b/Bugzilla/JobQueue.pm
@@ -13,7 +13,10 @@ use strict;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Install::Util qw(install_string);
-use parent qw(TheSchwartz);
+use File::Basename;
+use File::Slurp;
+use base qw(TheSchwartz);
+use fields qw(_worker_pidfile);
# This maps job names for Bugzilla::JobQueue to the appropriate modules.
# If you add new types of jobs, you should add a mapping here.
@@ -93,6 +96,57 @@ sub insert {
return $retval;
}
+# To avoid memory leaks/fragmentation which tends to happen for long running
+# perl processes; check for jobs, and spawn a new process to empty the queue.
+sub subprocess_worker {
+ my $self = shift;
+
+ my $command = "$0 -d -p '" . $self->{_worker_pidfile} . "' onepass";
+
+ while (1) {
+ my $time = (time);
+ my @jobs = $self->list_jobs({
+ funcname => $self->{all_abilities},
+ run_after => $time,
+ grabbed_until => $time,
+ limit => 1,
+ });
+ if (@jobs) {
+ $self->debug("Spawning queue worker process");
+ # Run the worker as a daemon
+ system $command;
+ # And poll the PID to detect when the working has finished.
+ # We do this instead of system() to allow for the INT signal to
+ # interrup us and trigger kill_worker().
+ my $pid = read_file($self->{_worker_pidfile}, err_mode => 'quiet');
+ if ($pid) {
+ sleep(3) while(kill(0, $pid));
+ }
+ $self->debug("Queue worker process completed");
+ } else {
+ $self->debug("No jobs found");
+ }
+ sleep(5);
+ }
+}
+
+sub kill_worker {
+ my $self = Bugzilla->job_queue();
+ if ($self->{_worker_pidfile} && -e $self->{_worker_pidfile}) {
+ my $worker_pid = read_file($self->{_worker_pidfile});
+ if ($worker_pid && kill(0, $worker_pid)) {
+ $self->debug("Stopping worker process");
+ system "$0 -f -p '" . $self->{_worker_pidfile} . "' stop";
+ }
+ }
+}
+
+sub set_pidfile {
+ my ($self, $pidfile) = @_;
+ $self->{_worker_pidfile} = bz_locations->{'datadir'} .
+ '/worker-' . basename($pidfile);
+}
+
# Clear the request cache at the start of each run.
sub work_once {
my $self = shift;
@@ -136,4 +190,8 @@ be sent away to be done later.
=item job_map
+=item set_pidfile
+
+=item kill_worker
+
=back