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

(-)a/Koha/BackgroundJob.pm (+87 lines)
Lines 1-5 Link Here
1
package Koha::BackgroundJob;
1
package Koha::BackgroundJob;
2
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
3
use Modern::Perl;
18
use Modern::Perl;
4
use JSON qw( encode_json decode_json );
19
use JSON qw( encode_json decode_json );
5
use Carp qw( croak );
20
use Carp qw( croak );
Lines 13-18 use Koha::BackgroundJob::BatchUpdateAuthority; Link Here
13
28
14
use base qw( Koha::Object );
29
use base qw( Koha::Object );
15
30
31
=head1 NAME
32
33
Koha::BackgroundJob - Koha BackgroundJob Object class
34
35
This is a base class for BackgroundJob, some methods must be subclassed.
36
37
Example of usage:
38
39
Producer:
40
my $job_id = Koha::BackgroundJob->enqueue(
41
    {
42
        job_type => $job_type,
43
        job_size => $job_size,
44
        job_args => $job_args
45
    }
46
);
47
48
Consumer:
49
Koha::BackgrounJobs->find($job_id)->process;
50
See also C<misc/background_jobs_worker.pl> for a full example
51
52
=head1 API
53
54
=head2 Class methods
55
56
=head3 connect
57
58
Connect to the message broker using default guest/guest credential
59
60
=cut
61
16
sub connect {
62
sub connect {
17
    my ( $self );
63
    my ( $self );
18
    my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
64
    my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
Lines 20-25 sub connect { Link Here
20
    return $stomp;
66
    return $stomp;
21
}
67
}
22
68
69
=head3 enqueue
70
71
Enqueue a new job. It will insert a new row in the DB table and notify the broker that a new job has been enqueued.
72
73
C<job_size> is the size of the job
74
C<job_args> is the arguments of the job. It's a structure that will be JSON encoded.
75
76
Return the job_id of the newly created job.
77
78
=cut
79
23
sub enqueue {
80
sub enqueue {
24
    my ( $self, $params ) = @_;
81
    my ( $self, $params ) = @_;
25
82
Lines 61-66 sub enqueue { Link Here
61
    return $job_id;
118
    return $job_id;
62
}
119
}
63
120
121
=head3 process
122
123
Process the job!
124
125
=cut
126
64
sub process {
127
sub process {
65
    my ( $self, $args ) = @_;
128
    my ( $self, $args ) = @_;
66
129
Lines 72-79 sub process { Link Here
72
      : Koha::Exceptions::Exception->throw('->process called without valid job_type');
135
      : Koha::Exceptions::Exception->throw('->process called without valid job_type');
73
}
136
}
74
137
138
=head3 job_type
139
140
Return the job type of the job. Must be a string.
141
142
=cut
143
75
sub job_type { croak "This method must be subclassed" }
144
sub job_type { croak "This method must be subclassed" }
76
145
146
=head3 messages
147
148
Messages let during the processing of the job.
149
150
=cut
151
77
sub messages {
152
sub messages {
78
    my ( $self ) = @_;
153
    my ( $self ) = @_;
79
154
Lines 86-91 sub messages { Link Here
86
    return @messages;
161
    return @messages;
87
}
162
}
88
163
164
=head3 report
165
166
Report of the job.
167
168
=cut
169
89
sub report {
170
sub report {
90
    my ( $self ) = @_;
171
    my ( $self ) = @_;
91
172
Lines 93-98 sub report { Link Here
93
    return $data_dump->{report};
174
    return $data_dump->{report};
94
}
175
}
95
176
177
=head3 cancel
178
179
Cancel a job.
180
181
=cut
182
96
sub cancel {
183
sub cancel {
97
    my ( $self ) = @_;
184
    my ( $self ) = @_;
98
    $self->status('cancelled')->store;
185
    $self->status('cancelled')->store;
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (+43 lines)
Lines 1-5 Link Here
1
package Koha::BackgroundJob::BatchUpdateAuthority;
1
package Koha::BackgroundJob::BatchUpdateAuthority;
2
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
3
use Modern::Perl;
18
use Modern::Perl;
4
use JSON qw( encode_json decode_json );
19
use JSON qw( encode_json decode_json );
5
20
Lines 11-20 use Koha::MetadataRecord::Authority; Link Here
11
26
12
use base 'Koha::BackgroundJob';
27
use base 'Koha::BackgroundJob';
13
28
29
=head1 NAME
30
31
Koha::BackgroundJob::BatchUpdateAuthority - Batch update authorities
32
33
This is a subclass of Koha::BackgroundJob.
34
35
=head1 API
36
37
=head2 Class methods
38
39
=head3 job_type
40
41
Define the job type of this job: batch_authority_record_modification
42
43
=cut
44
14
sub job_type {
45
sub job_type {
15
    return 'batch_authority_record_modification';
46
    return 'batch_authority_record_modification';
16
}
47
}
17
48
49
=head3 process
50
51
Process the modification.
52
53
=cut
54
18
sub process {
55
sub process {
19
    my ( $self, $args ) = @_;
56
    my ( $self, $args ) = @_;
20
57
Lines 79-84 sub process { Link Here
79
116
80
}
117
}
81
118
119
=head3 enqueue
120
121
Enqueue the new job
122
123
=cut
124
82
sub enqueue {
125
sub enqueue {
83
    my ( $self, $args) = @_;
126
    my ( $self, $args) = @_;
84
127
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (+43 lines)
Lines 1-5 Link Here
1
package Koha::BackgroundJob::BatchUpdateBiblio;
1
package Koha::BackgroundJob::BatchUpdateBiblio;
2
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
3
use Modern::Perl;
18
use Modern::Perl;
4
use JSON qw( encode_json decode_json );
19
use JSON qw( encode_json decode_json );
5
20
Lines 10-19 use C4::MarcModificationTemplates; Link Here
10
25
11
use base 'Koha::BackgroundJob';
26
use base 'Koha::BackgroundJob';
12
27
28
=head1 NAME
29
30
Koha::BackgroundJob::BatchUpdateBiblio - Batch update bibliographic records
31
32
This is a subclass of Koha::BackgroundJob.
33
34
=head1 API
35
36
=head2 Class methods
37
38
=head3 job_type
39
40
Define the job type of this job: batch_biblio_record_modification
41
42
=cut
43
13
sub job_type {
44
sub job_type {
14
    return 'batch_biblio_record_modification';
45
    return 'batch_biblio_record_modification';
15
}
46
}
16
47
48
=head3 process
49
50
Process the modification.
51
52
=cut
53
17
sub process {
54
sub process {
18
    my ( $self, $args ) = @_;
55
    my ( $self, $args ) = @_;
19
56
Lines 86-91 sub process { Link Here
86
    $job->store;
123
    $job->store;
87
}
124
}
88
125
126
=head3 enqueue
127
128
Enqueue the new job
129
130
=cut
131
89
sub enqueue {
132
sub enqueue {
90
    my ( $self, $args) = @_;
133
    my ( $self, $args) = @_;
91
134
(-)a/Koha/BackgroundJobs.pm (+33 lines)
Lines 1-13 Link Here
1
package Koha::BackgroundJobs;
1
package Koha::BackgroundJobs;
2
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
3
use Modern::Perl;
18
use Modern::Perl;
4
use base qw(Koha::Objects);
19
use base qw(Koha::Objects);
5
use Koha::BackgroundJob;
20
use Koha::BackgroundJob;
6
21
22
=head1 NAME
23
24
Koha::BackgroundJobs - Koha BackgroundJob Object set class
25
26
=head1 API
27
28
=head2 Class Methods
29
30
=cut
31
32
=head3 _type
33
34
=cut
35
7
sub _type {
36
sub _type {
8
    return 'BackgroundJob';
37
    return 'BackgroundJob';
9
}
38
}
10
39
40
=head3 object_class
41
42
=cut
43
11
sub object_class {
44
sub object_class {
12
    return 'Koha::BackgroundJob';
45
    return 'Koha::BackgroundJob';
13
}
46
}
(-)a/admin/background_jobs.pl (-1 lines)
Lines 39-45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
39
        template_name   => "admin/background_jobs.tt",
39
        template_name   => "admin/background_jobs.tt",
40
        query           => $input,
40
        query           => $input,
41
        type            => "intranet",
41
        type            => "intranet",
42
        authnotrequired => 0,
43
        flagsrequired   => $flags_required,
42
        flagsrequired   => $flags_required,
44
        debug           => 1,
43
        debug           => 1,
45
    }
44
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt (-5 / +4 lines)
Lines 24-30 Link Here
24
    <div class="dialog message">
24
    <div class="dialog message">
25
        [% SWITCH m.code %]
25
        [% SWITCH m.code %]
26
        [% CASE 'cannot_retrieve_jobs' %]
26
        [% CASE 'cannot_retrieve_jobs' %]
27
            <div><i class="fa fa-exclamation error"></i>Cannot retrieve pending jobs ([% m.error %])</div>
27
            <div><i class="fa fa-exclamation error"></i>Cannot retrieve pending jobs ([% m.error | html %])</div>
28
        [% CASE 'cannot_view_job' %]
28
        [% CASE 'cannot_view_job' %]
29
            <div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
29
            <div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
30
        [% CASE %]
30
        [% CASE %]
Lines 104-110 Link Here
104
                            [% END %]
104
                            [% END %]
105
                            [% SWITCH m.code %]
105
                            [% SWITCH m.code %]
106
                            [% CASE 'biblio_not_modified' %]
106
                            [% CASE 'biblio_not_modified' %]
107
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has not been modified. An error occurred on modifying it.[% IF m.error %] ([% m.error %])[% END %].
107
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has not been modified. An error occurred on modifying it.[% IF m.error %] ([% m.error | html %])[% END %].
108
                            [% CASE 'biblio_modified' %]
108
                            [% CASE 'biblio_modified' %]
109
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
109
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
110
                            [% END %]
110
                            [% END %]
Lines 122-128 Link Here
122
                            [% END %]
122
                            [% END %]
123
                            [% SWITCH m.code %]
123
                            [% SWITCH m.code %]
124
                            [% CASE 'authority_not_modified' %]
124
                            [% CASE 'authority_not_modified' %]
125
                                Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% m.authid | uri %]">[% m.authid | html %]</a> has not been modified. An error occurred on modifying it[% IF m.error %] ([% m.error %])[% END %].
125
                                Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% m.authid | uri %]">[% m.authid | html %]</a> has not been modified. An error occurred on modifying it[% IF m.error %] ([% m.error | html %])[% END %].
126
                            [% CASE 'authority_modified' %]
126
                            [% CASE 'authority_modified' %]
127
                                Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% m.authid | uri %]">[% m.authid | html %]</a> has successfully been modified..
127
                                Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% m.authid | uri %]">[% m.authid | html %]</a> has successfully been modified..
128
                            [% END %]
128
                            [% END %]
Lines 146-152 Link Here
146
    <div class="dialog message">
146
    <div class="dialog message">
147
        <i class="fa fa-info"></i>
147
        <i class="fa fa-info"></i>
148
        [% IF pending_jobs.size > 0 %]
148
        [% IF pending_jobs.size > 0 %]
149
            There is [% pending_jobs.size %] pending jobs on the server: [% pending_jobs.join(', ') %].
149
            There is [% pending_jobs.size | html %] pending jobs on the server: [% pending_jobs.join(', ') | html %].
150
        [% ELSE %]
150
        [% ELSE %]
151
            There is no pending jobs on the server.
151
            There is no pending jobs on the server.
152
        [% END %]
152
        [% END %]
153
- 

Return to bug 22417