|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use JSON qw( encode_json decode_json ); |
| 5 |
|
| 6 |
use Koha::BackgroundJob; |
| 7 |
|
| 8 |
my $conn = Koha::BackgroundJob->connect; |
| 9 |
|
| 10 |
my @job_types = qw( batch_biblio_record_modification batch_authority_record_modification ); |
| 11 |
|
| 12 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
| 13 |
my $namespace = C4::Context->config('memcached_namespace'); |
| 14 |
for my $job_type ( @job_types ) { |
| 15 |
$conn->subscribe({ destination => sprintf("%s-%s", $namespace, $job_type), ack => 'client' }); |
| 16 |
} |
| 17 |
while (1) { |
| 18 |
my $frame = $conn->receive_frame; |
| 19 |
if ( !defined $frame ) { |
| 20 |
# maybe log connection problems |
| 21 |
next; # will reconnect automatically |
| 22 |
} |
| 23 |
|
| 24 |
my $body = $frame->body; |
| 25 |
say " [x] Received $body"; |
| 26 |
my $args = decode_json($body); |
| 27 |
|
| 28 |
# FIXME This means we need to have create the DB entry before |
| 29 |
# It could work in a first step, but then we will want to handle job that will be created from the message received |
| 30 |
my $job = Koha::BackgroundJobs->find($args->{job_id}); |
| 31 |
my $success = $job->process( $args ); |
| 32 |
say " [x] Done"; |
| 33 |
|
| 34 |
$conn->ack( { frame => $frame } ); # FIXME depending on $success? |
| 35 |
} |
| 36 |
$conn->disconnect; |