<vhost>__MESSAGE_BROKER_VHOST__</vhost>
</message_broker>
+ <background_jobs_worker>
+ <!-- Max simultaneous processes per worker -->
+ <max_processes>1</max_processes>
+ </background_jobs_worker>
+
<do_not_remove_cookie>__KEEP_COOKIE__</do_not_remove_cookie>
<do_not_remove_cookie>catalogue_editor_\d+</do_not_remove_cookie>
<!-- Uncomment lines like hereunder to not clear cookies at logout:
<vhost></vhost>
</message_broker>
+ <background_jobs_worker>
+ <!-- Max simultaneous processes per worker -->
+ <max_processes>1</max_processes>
+ </background_jobs_worker>
+
<do_not_remove_cookie>catalogue_editor_\d+</do_not_remove_cookie>
<!-- Uncomment lines like hereunder to not clear cookies at logout:
The cookie name is case sensitive.
=head1 SYNOPSIS
-./background_jobs_worker.pl [--queue QUEUE]
+./background_jobs_worker.pl [--queue QUEUE] [-m|--max-processes MAX_PROCESSES]
=head1 DESCRIPTION
You can specify some queues only (using --queue, which is repeatable) if you want to run several workers that will handle their own jobs.
+--m --max-processes specifies how many jobs to process simultaneously
+
+Max processes will be set from the command line option, the environment variable MAX_PROCESSES, or the koha-conf file, in that order of precedence.
+By default the script will only run one job at a time.
+
=head1 OPTIONS
=over
use Try::Tiny;
use Pod::Usage;
use Getopt::Long;
+use Parallel::ForkManager;
use C4::Context;
use Koha::Logger;
use Koha::BackgroundJobs;
+use C4::Context;
my ( $help, @queues );
+
+my $max_processes = $ENV{MAX_PROCESSES};
+$max_processes ||= C4::Context->config('background_jobs_worker')->{max_processes} if C4::Context->config('background_jobs_worker');
+$max_processes ||= 1;
+
GetOptions(
+ 'm|max-processes=i' => \$max_processes,
'h|help' => \$help,
'queue=s' => \@queues,
) || pod2usage(1);
+
pod2usage(0) if $help;
unless (@queues) {
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_;
};
+my $pm = Parallel::ForkManager->new($max_processes);
+
if ( $conn ) {
# FIXME cf note in Koha::BackgroundJob about $namespace
my $namespace = C4::Context->config('memcached_namespace');
next;
}
+ $pm->start and next;
process_job( $job, $args );
+ $pm->finish;
} else {
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
next unless $args;
+ $pm->start and next;
process_job( $job, { job_id => $job->id, %$args } );
+ $pm->finish;
}
sleep 10;