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

(-)a/Koha/BackgroundJob.pm (-23 / +6 lines)
Lines 3-9 package Koha::BackgroundJob; 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
use Carp qw( croak );
5
use Carp qw( croak );
6
use Net::RabbitFoot;
6
use Net::Stomp;
7
7
8
use C4::Context;
8
use C4::Context;
9
use Koha::DateUtils qw( dt_from_string );
9
use Koha::DateUtils qw( dt_from_string );
Lines 13-27 use base qw( Koha::Object ); Link Here
13
13
14
sub connect {
14
sub connect {
15
    my ( $self );
15
    my ( $self );
16
    my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
16
    my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
17
        host => 'localhost', # TODO Move this to KOHA_CONF
17
    $stomp->connect( { login => 'guest', passcode => 'guest' } );
18
        port => 5672,
18
    return $stomp;
19
        user => 'guest',
20
        pass => 'guest',
21
        vhost => '/',
22
    );
23
24
    return $conn;
25
}
19
}
26
20
27
sub enqueue {
21
sub enqueue {
Lines 47-65 sub enqueue { Link Here
47
    $json_args = encode_json $job_args,
41
    $json_args = encode_json $job_args,
48
42
49
    my $conn = $self->connect;
43
    my $conn = $self->connect;
50
    my $channel = $conn->open_channel();
44
    $conn->send({destination => $job_type, body => $json_args});
51
45
52
    $channel->declare_queue(
53
        queue => $job_type,
54
        durable => 1,
55
    );
56
57
    $channel->publish(
58
        exchange => '',
59
        routing_key => $job_type, # TODO Must be different?
60
        body => $json_args,
61
    );
62
    $conn->close;
63
    return $job_id;
46
    return $job_id;
64
}
47
}
65
48
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-1 lines)
Lines 4-10 use Modern::Perl; Link Here
4
use Koha::BackgroundJobs;
4
use Koha::BackgroundJobs;
5
use Koha::DateUtils qw( dt_from_string );
5
use Koha::DateUtils qw( dt_from_string );
6
use JSON qw( encode_json decode_json );
6
use JSON qw( encode_json decode_json );
7
use Net::RabbitFoot;
8
7
9
use base 'Koha::BackgroundJob';
8
use base 'Koha::BackgroundJob';
10
9
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-5 / +1 lines)
Lines 4-23 use Modern::Perl; Link Here
4
use Koha::BackgroundJobs;
4
use Koha::BackgroundJobs;
5
use Koha::DateUtils qw( dt_from_string );
5
use Koha::DateUtils qw( dt_from_string );
6
use JSON qw( encode_json decode_json );
6
use JSON qw( encode_json decode_json );
7
use Net::RabbitFoot;
8
7
9
use base 'Koha::BackgroundJob';
8
use base 'Koha::BackgroundJob';
10
9
11
our $channel;
12
sub process {
10
sub process {
13
    my ( $self, $args, $channel ) = @_;
11
    my ( $self, $args ) = @_;
14
12
15
    my $job_type = $args->{job_type};
13
    my $job_type = $args->{job_type};
16
14
17
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
15
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
18
16
19
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
17
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
20
        $channel->ack;
21
        return;
18
        return;
22
    }
19
    }
23
20
Lines 77-83 sub process { Link Here
77
        ->data(encode_json $job_data);
74
        ->data(encode_json $job_data);
78
    $job->status('finished') if $job->status ne 'cancelled';
75
    $job->status('finished') if $job->status ne 'cancelled';
79
    $job->store;
76
    $job->store;
80
    $channel->ack(); # FIXME Is that ok even on failure?
81
}
77
}
82
78
83
sub enqueue {
79
sub enqueue {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt (-4 / +4 lines)
Lines 141-149 Link Here
141
                    <td class="actions">
141
                    <td class="actions">
142
                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
142
                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
143
                        [% IF job.status == 'new' || job.status == 'started' %]
143
                        [% IF job.status == 'new' || job.status == 'started' %]
144
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-pencil"></i> Cancel</a>
144
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
145
                        [% END %]
145
                        [% END %]
146
                        <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a>
146
                        <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&amp;id=[% job.id | html %]"><i class="fa fa-refresh"></i> Replay</a>
147
                    </td>
147
                    </td>
148
                </tr>
148
                </tr>
149
                [% END %]
149
                [% END %]
Lines 171-181 Link Here
171
    [% INCLUDE 'datatables.inc' %]
171
    [% INCLUDE 'datatables.inc' %]
172
    <script>
172
    <script>
173
        $(document).ready(function() {
173
        $(document).ready(function() {
174
            $("#table_cities").dataTable($.extend(true, {}, dataTablesDefaults, {
174
            $("#table_background_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
175
                "aoColumnDefs": [
175
                "aoColumnDefs": [
176
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
176
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
177
                ],
177
                ],
178
                "aaSorting": [[ 1, "asc" ]],
178
                "aaSorting": [[ 0, "desc" ]],
179
                "iDisplayLength": 10,
179
                "iDisplayLength": 10,
180
                "sPaginationType": "full_numbers"
180
                "sPaginationType": "full_numbers"
181
            }));
181
            }));
(-)a/misc/background_jobs_worker.pl (-26 / +17 lines)
Lines 23-52 use Koha::BackgroundJob; Link Here
23
23
24
my $conn = Koha::BackgroundJob->connect;
24
my $conn = Koha::BackgroundJob->connect;
25
25
26
my $channel = $conn->open_channel();
27
28
my $job_type = 'batch_biblio_record_modification';
26
my $job_type = 'batch_biblio_record_modification';
29
$channel->declare_queue(
27
30
    queue => $job_type,
28
$conn->subscribe({ destination => $job_type, ack => 'client' });
31
    durable => 1,
29
while (1) {
32
);
30
    my $frame = $conn->receive_frame;
33
31
    if ( !defined $frame ) {
34
$channel->qos(prefetch_count => 1,);
32
        # maybe log connection problems
35
33
        next;    # will reconnect automatically
36
$channel->consume(
34
    }
37
    on_consume => sub {
35
38
        my $var = shift;
36
    my $body = $frame->body;
39
        my $body = $var->{body}->{payload};
37
    my $args = decode_json($body);
40
        say " [x] Received $body";
38
41
39
    my $success = Koha::BackgroundJob::BatchUpdateBiblio->process( $args );
42
        my $args = decode_json( $body );
40
43
41
    $conn->ack( { frame => $frame } ); # FIXME depending on $success?
44
        Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel);
42
}
45
        say " [x] Done";
43
$conn->disconnect;
46
    },
47
    no_ack => 0,
48
);
49
50
warn "waiting forever";
51
# Wait forever
52
AnyEvent->condvar->recv;
(-)a/tools/batch_record_modification.pl (-2 lines)
Lines 23-29 use Modern::Perl; Link Here
23
use CGI;
23
use CGI;
24
use List::MoreUtils qw( uniq );
24
use List::MoreUtils qw( uniq );
25
use JSON qw( encode_json );
25
use JSON qw( encode_json );
26
use Net::RabbitFoot;
27
26
28
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
29
use C4::Output qw( output_html_with_http_headers );
28
use C4::Output qw( output_html_with_http_headers );
30
- 

Return to bug 22417