]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1441181 - Step 6 - Add concurrency
authorDylan William Hardison <dylan@hardison.net>
Tue, 13 Mar 2018 14:45:01 +0000 (10:45 -0400)
committerGitHub <noreply@github.com>
Tue, 13 Mar 2018 14:45:01 +0000 (10:45 -0400)
Bugzilla/JobQueue/Runner.pm
jobqueue.pl

index a3cf3ff55d5e0cbe5ffe3ecb47717708d1496383..1c74bc28fe6da201704bd5b31cfd8dbb52c98534 100644 (file)
@@ -28,6 +28,7 @@ use File::Basename;
 use File::Copy;
 use File::Spec::Functions qw(catfile);
 use Future;
+use Future::Utils qw(fmap_void);
 use IO::Async::Loop;
 use IO::Async::Process;
 use IO::Async::Signal;
@@ -94,6 +95,7 @@ sub gd_more_opt {
     return (
         'pidfile=s' => \$self->{gd_args}{pidfile},
         'n=s'       => \$self->{gd_args}{progname},
+        'jobs|j=i'  => \$self->{gd_args}{jobs},
     );
 }
 
@@ -206,13 +208,18 @@ sub gd_quit_event     { FATAL('gd_quit_event() should never be called') }
 sub gd_reconfig_event { FATAL('gd_reconfig_event() should never be called') }
 
 sub gd_run {
-    my $self = shift;
+    my $self      = shift;
+    my $jobs      = $self->{gd_args}{jobs} // 1;
+    my $signal_f  = $self->{_signal_future};
+    my $workers_f = fmap_void { $self->run_worker("work") }
+        concurrent => $jobs,
+        generate   => sub { !$signal_f->is_ready };
 
     # This is so the process shows up in (h)top in a useful way.
     local $PROGRAM_NAME = "$self->{gd_progname} [supervisor]";
-    my $code = $self->run_worker('work')->get;
+    Future->wait_any($signal_f, $workers_f)->get;
     unlink $self->{gd_pidfile};
-    exit $code;
+    exit 0;
 }
 
 # This executes the script "jobqueue-worker.pl"
index d9791b3d45e14473583a9660ea8aeda29e926ef5..7a884b8110a519ef573cdfc5bdc0d74f651e6853 100755 (executable)
@@ -40,6 +40,8 @@ jobqueue.pl - Runs jobs in the background for Bugzilla.
              process id. Defaults to F<data/jobqueue.pl.pid>.
    -n name   What should this process call itself in the system log?
              Defaults to the full path you used to invoke the script.
+   -j jobs   How many child processes should be run?
+             Defaults to 1.
 
    COMMANDS:
    start     Starts a new jobqueue daemon if there isn't one running already