|
Lines 15-26
Link Here
|
| 15 |
# You should have received a copy of the GNU General Public License |
15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
|
|
18 |
=head1 NAME |
| 19 |
|
| 20 |
background_jobs_worker.pl - Worker script that will process backgroung jobs |
| 21 |
|
| 22 |
=head1 SYNOPSIS |
| 23 |
|
| 24 |
./background_jobs_worker.pl [--job-type] |
| 25 |
|
| 26 |
=head1 DESCRIPTION |
| 27 |
|
| 28 |
This script will connect to the Stomp server (RabbitMQ) and subscribe to the different destination queues available. |
| 29 |
You can specify some queues only (using --job-type) if you want to run several workers that will handle their own jobs. |
| 30 |
|
| 31 |
=head1 OPTIONS |
| 32 |
|
| 33 |
=over |
| 34 |
|
| 35 |
=item B<--job-type> |
| 36 |
|
| 37 |
Give the job types this worker will process. |
| 38 |
|
| 39 |
The different values available are: |
| 40 |
|
| 41 |
batch_biblio_record_modification |
| 42 |
batch_authority_record_modification |
| 43 |
update_elastic_index |
| 44 |
|
| 45 |
=back |
| 46 |
|
| 47 |
=cut |
| 48 |
|
| 18 |
use Modern::Perl; |
49 |
use Modern::Perl; |
| 19 |
use JSON qw( decode_json ); |
50 |
use JSON qw( decode_json ); |
| 20 |
use Try::Tiny qw( catch try ); |
51 |
use Try::Tiny qw( catch try ); |
|
|
52 |
use Pod::Usage; |
| 53 |
use Getopt::Long; |
| 21 |
|
54 |
|
| 22 |
use Koha::BackgroundJobs; |
55 |
use Koha::BackgroundJobs; |
| 23 |
|
56 |
|
|
|
57 |
my ( $help, @job_types ); |
| 58 |
GetOptions( |
| 59 |
'h|help' => \$help, |
| 60 |
'job-type:s' => \@job_types, |
| 61 |
) || pod2usage(1); |
| 62 |
|
| 63 |
pod2usage(0) if $help; |
| 64 |
|
| 24 |
my $conn; |
65 |
my $conn; |
| 25 |
try { |
66 |
try { |
| 26 |
$conn = Koha::BackgroundJob->connect; |
67 |
$conn = Koha::BackgroundJob->connect; |
|
Lines 28-34
try {
Link Here
|
| 28 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
69 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
| 29 |
}; |
70 |
}; |
| 30 |
|
71 |
|
| 31 |
my @job_types = qw( |
72 |
my @available_job_types = qw( |
| 32 |
batch_biblio_record_modification |
73 |
batch_biblio_record_modification |
| 33 |
batch_authority_record_modification |
74 |
batch_authority_record_modification |
| 34 |
batch_item_record_modification |
75 |
batch_item_record_modification |
|
Lines 39-44
my @job_types = qw(
Link Here
|
| 39 |
update_elastic_index |
80 |
update_elastic_index |
| 40 |
); |
81 |
); |
| 41 |
|
82 |
|
|
|
83 |
if ( @job_types ) { |
| 84 |
for my $job_type ( @job_types ) { |
| 85 |
pod2usage( -verbose => 1, -msg => sprintf "You specify an invalid --job-type value: %s\n", $job_type ) |
| 86 |
unless grep { $_ eq $job_type } @available_job_types; |
| 87 |
} |
| 88 |
} else { |
| 89 |
@job_types = @available_job_types; |
| 90 |
} |
| 91 |
|
| 42 |
if ( $conn ) { |
92 |
if ( $conn ) { |
| 43 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
93 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
| 44 |
my $namespace = C4::Context->config('memcached_namespace'); |
94 |
my $namespace = C4::Context->config('memcached_namespace'); |
| 45 |
- |
|
|