View | Details | Raw Unified | Return to bug 22417
Collapse All | Expand All

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

Return to bug 22417