Lines 52-67
use JSON qw( decode_json );
Link Here
|
52 |
use Try::Tiny; |
52 |
use Try::Tiny; |
53 |
use Pod::Usage; |
53 |
use Pod::Usage; |
54 |
use Getopt::Long; |
54 |
use Getopt::Long; |
|
|
55 |
use Parallel::ForkManager; |
55 |
|
56 |
|
56 |
use Koha::Logger; |
57 |
use Koha::Logger; |
57 |
use Koha::BackgroundJobs; |
58 |
use Koha::BackgroundJobs; |
|
|
59 |
use C4::Context; |
58 |
|
60 |
|
59 |
my ( $help, @queues ); |
61 |
my ( $help, @queues ); |
|
|
62 |
|
63 |
my $max_processes = $ENV{MAX_PROCESSES}; |
64 |
$max_processes ||= C4::Context->config('background_jobs_worker')->{max_processes} if C4::Context->config('background_jobs_worker'); |
65 |
$max_processes ||= 1; |
66 |
|
60 |
GetOptions( |
67 |
GetOptions( |
|
|
68 |
'm|max-processes=i' => \$max_processes, |
61 |
'h|help' => \$help, |
69 |
'h|help' => \$help, |
62 |
'queue=s' => \@queues, |
70 |
'queue=s' => \@queues, |
63 |
) || pod2usage(1); |
71 |
) || pod2usage(1); |
64 |
|
72 |
|
|
|
73 |
warn "MAX PROCEDS: $max_processes"; |
74 |
|
65 |
pod2usage(0) if $help; |
75 |
pod2usage(0) if $help; |
66 |
|
76 |
|
67 |
unless (@queues) { |
77 |
unless (@queues) { |
Lines 75-80
try {
Link Here
|
75 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
85 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
76 |
}; |
86 |
}; |
77 |
|
87 |
|
|
|
88 |
my $pm = Parallel::ForkManager->new($max_processes); |
89 |
|
78 |
if ( $conn ) { |
90 |
if ( $conn ) { |
79 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
91 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
80 |
my $namespace = C4::Context->config('memcached_namespace'); |
92 |
my $namespace = C4::Context->config('memcached_namespace'); |
Lines 115-121
while (1) {
Link Here
|
115 |
next; |
127 |
next; |
116 |
} |
128 |
} |
117 |
|
129 |
|
|
|
130 |
$pm->start and next; |
118 |
process_job( $job, $args ); |
131 |
process_job( $job, $args ); |
|
|
132 |
$pm->finish; |
119 |
|
133 |
|
120 |
} else { |
134 |
} else { |
121 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
135 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
Lines 130-136
while (1) {
Link Here
|
130 |
|
144 |
|
131 |
next unless $args; |
145 |
next unless $args; |
132 |
|
146 |
|
|
|
147 |
$pm->start and next; |
133 |
process_job( $job, { job_id => $job->id, %$args } ); |
148 |
process_job( $job, { job_id => $job->id, %$args } ); |
|
|
149 |
$pm->finish; |
134 |
|
150 |
|
135 |
} |
151 |
} |
136 |
sleep 10; |
152 |
sleep 10; |
137 |
- |
|
|