Bug 22417: Fix the batch authority tool
[koha.git] / misc / background_jobs_worker.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
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>.
17
18 use Modern::Perl;
19 use JSON qw( encode_json decode_json );
20
21 use Koha::BackgroundJobs;
22
23 my $conn = Koha::BackgroundJob->connect;
24
25 my @job_types = qw( batch_biblio_record_modification batch_authority_record_modification );
26
27 for my $job_type ( @job_types ) {
28     $conn->subscribe({ destination => $job_type, ack => 'client' });
29 }
30 while (1) {
31     my $frame = $conn->receive_frame;
32     if ( !defined $frame ) {
33         # maybe log connection problems
34         next;    # will reconnect automatically
35     }
36
37     my $body = $frame->body;
38     my $args = decode_json($body);
39
40     # FIXME This means we need to have create the DB entry before
41     # It could work in a first step, but then we will want to handle job that will be created from the message received
42     my $job = Koha::BackgroundJobs->find($args->{job_id});
43     my $success = $job->process( $args );
44
45     $conn->ack( { frame => $frame } ); # FIXME depending on $success?
46 }
47 $conn->disconnect;