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

(-)a/koha_worker.pl (+36 lines)
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;
(-)a/new_koha_job.pl (-1 / +23 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use C4::Context;
5
use Koha::BackgroundJob::BatchUpdateBiblio;
6
7
my $mmtid       = 1;
8
my $record_type = 'biblio';
9
my @record_ids  = ( 1, 2, 3 );
10
11
C4::Context->_new_userenv(42);
12
C4::Context->set_userenv( 51, 51, 42, 'koha', 'koha', 'CPL', 'CPL', 1 );
13
14
say " [x] Enqueuing BatchUpdateBiblio mmtid=$mmtid with biblionumber="
15
  . join( ',', @record_ids );
16
Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue(
17
    {
18
        job_type    => 'batch_record_modification',
19
        mmtid       => $mmtid,
20
        record_type => $record_type,
21
        record_ids  => \@record_ids,
22
    }
23
);

Return to bug 22417