Lines 21-27
background_jobs_worker.pl - Worker script that will process background jobs
Link Here
|
21 |
|
21 |
|
22 |
=head1 SYNOPSIS |
22 |
=head1 SYNOPSIS |
23 |
|
23 |
|
24 |
./background_jobs_worker.pl [--queue QUEUE] |
24 |
./background_jobs_worker.pl [--queue QUEUE] [-m|--max-processes MAX_PROCESSES] |
25 |
|
25 |
|
26 |
=head1 DESCRIPTION |
26 |
=head1 DESCRIPTION |
27 |
|
27 |
|
Lines 30-35
or if a Stomp server is not active it will poll the database every 10s for new j
Link Here
|
30 |
|
30 |
|
31 |
You can specify some queues only (using --queue, which is repeatable) if you want to run several workers that will handle their own jobs. |
31 |
You can specify some queues only (using --queue, which is repeatable) if you want to run several workers that will handle their own jobs. |
32 |
|
32 |
|
|
|
33 |
--m --max-processes specifies how many jobs to process simultaneously |
34 |
|
35 |
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. |
36 |
By default the script will only run one job at a time. |
37 |
|
33 |
=head1 OPTIONS |
38 |
=head1 OPTIONS |
34 |
|
39 |
|
35 |
=over |
40 |
=over |
Lines 52-67
use JSON qw( decode_json );
Link Here
|
52 |
use Try::Tiny; |
57 |
use Try::Tiny; |
53 |
use Pod::Usage; |
58 |
use Pod::Usage; |
54 |
use Getopt::Long; |
59 |
use Getopt::Long; |
|
|
60 |
use Parallel::ForkManager; |
55 |
|
61 |
|
56 |
use Koha::Logger; |
62 |
use Koha::Logger; |
57 |
use Koha::BackgroundJobs; |
63 |
use Koha::BackgroundJobs; |
|
|
64 |
use C4::Context; |
58 |
|
65 |
|
59 |
my ( $help, @queues ); |
66 |
my ( $help, @queues ); |
|
|
67 |
|
68 |
my $max_processes = $ENV{MAX_PROCESSES}; |
69 |
$max_processes ||= C4::Context->config('background_jobs_worker')->{max_processes} if C4::Context->config('background_jobs_worker'); |
70 |
$max_processes ||= 1; |
71 |
|
60 |
GetOptions( |
72 |
GetOptions( |
|
|
73 |
'm|max-processes=i' => \$max_processes, |
61 |
'h|help' => \$help, |
74 |
'h|help' => \$help, |
62 |
'queue=s' => \@queues, |
75 |
'queue=s' => \@queues, |
63 |
) || pod2usage(1); |
76 |
) || pod2usage(1); |
64 |
|
77 |
|
|
|
78 |
|
65 |
pod2usage(0) if $help; |
79 |
pod2usage(0) if $help; |
66 |
|
80 |
|
67 |
unless (@queues) { |
81 |
unless (@queues) { |
Lines 75-80
try {
Link Here
|
75 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
89 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
76 |
}; |
90 |
}; |
77 |
|
91 |
|
|
|
92 |
my $pm = Parallel::ForkManager->new($max_processes); |
93 |
|
78 |
if ( $conn ) { |
94 |
if ( $conn ) { |
79 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
95 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
80 |
my $namespace = C4::Context->config('memcached_namespace'); |
96 |
my $namespace = C4::Context->config('memcached_namespace'); |
Lines 115-121
while (1) {
Link Here
|
115 |
next; |
131 |
next; |
116 |
} |
132 |
} |
117 |
|
133 |
|
|
|
134 |
$pm->start and next; |
118 |
process_job( $job, $args ); |
135 |
process_job( $job, $args ); |
|
|
136 |
$pm->finish; |
119 |
|
137 |
|
120 |
} else { |
138 |
} else { |
121 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
139 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
Lines 130-136
while (1) {
Link Here
|
130 |
|
148 |
|
131 |
next unless $args; |
149 |
next unless $args; |
132 |
|
150 |
|
|
|
151 |
$pm->start and next; |
133 |
process_job( $job, { job_id => $job->id, %$args } ); |
152 |
process_job( $job, { job_id => $job->id, %$args } ); |
|
|
153 |
$pm->finish; |
134 |
|
154 |
|
135 |
} |
155 |
} |
136 |
sleep 10; |
156 |
sleep 10; |
137 |
- |
|
|