package Koha::BackgroundJob;
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
use Modern::Perl;
use JSON qw( encode_json decode_json );
use Carp qw( croak );
use base qw( Koha::Object );
+=head1 NAME
+
+Koha::BackgroundJob - Koha BackgroundJob Object class
+
+This is a base class for BackgroundJob, some methods must be subclassed.
+
+Example of usage:
+
+Producer:
+my $job_id = Koha::BackgroundJob->enqueue(
+ {
+ job_type => $job_type,
+ job_size => $job_size,
+ job_args => $job_args
+ }
+);
+
+Consumer:
+Koha::BackgrounJobs->find($job_id)->process;
+See also C<misc/background_jobs_worker.pl> for a full example
+
+=head1 API
+
+=head2 Class methods
+
+=head3 connect
+
+Connect to the message broker using default guest/guest credential
+
+=cut
+
sub connect {
my ( $self );
my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
return $stomp;
}
+=head3 enqueue
+
+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.
+
+C<job_size> is the size of the job
+C<job_args> is the arguments of the job. It's a structure that will be JSON encoded.
+
+Return the job_id of the newly created job.
+
+=cut
+
sub enqueue {
my ( $self, $params ) = @_;
return $job_id;
}
+=head3 process
+
+Process the job!
+
+=cut
+
sub process {
my ( $self, $args ) = @_;
: Koha::Exceptions::Exception->throw('->process called without valid job_type');
}
+=head3 job_type
+
+Return the job type of the job. Must be a string.
+
+=cut
+
sub job_type { croak "This method must be subclassed" }
+=head3 messages
+
+Messages let during the processing of the job.
+
+=cut
+
sub messages {
my ( $self ) = @_;
return @messages;
}
+=head3 report
+
+Report of the job.
+
+=cut
+
sub report {
my ( $self ) = @_;
return $data_dump->{report};
}
+=head3 cancel
+
+Cancel a job.
+
+=cut
+
sub cancel {
my ( $self ) = @_;
$self->status('cancelled')->store;
package Koha::BackgroundJob::BatchUpdateAuthority;
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
use Modern::Perl;
use JSON qw( encode_json decode_json );
use base 'Koha::BackgroundJob';
+=head1 NAME
+
+Koha::BackgroundJob::BatchUpdateAuthority - Batch update authorities
+
+This is a subclass of Koha::BackgroundJob.
+
+=head1 API
+
+=head2 Class methods
+
+=head3 job_type
+
+Define the job type of this job: batch_authority_record_modification
+
+=cut
+
sub job_type {
return 'batch_authority_record_modification';
}
+=head3 process
+
+Process the modification.
+
+=cut
+
sub process {
my ( $self, $args ) = @_;
}
+=head3 enqueue
+
+Enqueue the new job
+
+=cut
+
sub enqueue {
my ( $self, $args) = @_;
package Koha::BackgroundJob::BatchUpdateBiblio;
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
use Modern::Perl;
use JSON qw( encode_json decode_json );
use base 'Koha::BackgroundJob';
+=head1 NAME
+
+Koha::BackgroundJob::BatchUpdateBiblio - Batch update bibliographic records
+
+This is a subclass of Koha::BackgroundJob.
+
+=head1 API
+
+=head2 Class methods
+
+=head3 job_type
+
+Define the job type of this job: batch_biblio_record_modification
+
+=cut
+
sub job_type {
return 'batch_biblio_record_modification';
}
+=head3 process
+
+Process the modification.
+
+=cut
+
sub process {
my ( $self, $args ) = @_;
$job->store;
}
+=head3 enqueue
+
+Enqueue the new job
+
+=cut
+
sub enqueue {
my ( $self, $args) = @_;
package Koha::BackgroundJobs;
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
use Modern::Perl;
use base qw(Koha::Objects);
use Koha::BackgroundJob;
+=head1 NAME
+
+Koha::BackgroundJobs - Koha BackgroundJob Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 _type
+
+=cut
+
sub _type {
return 'BackgroundJob';
}
+=head3 object_class
+
+=cut
+
sub object_class {
return 'Koha::BackgroundJob';
}
template_name => "admin/background_jobs.tt",
query => $input,
type => "intranet",
- authnotrequired => 0,
flagsrequired => $flags_required,
debug => 1,
}
<div class="dialog message">
[% SWITCH m.code %]
[% CASE 'cannot_retrieve_jobs' %]
- <div><i class="fa fa-exclamation error"></i>Cannot retrieve pending jobs ([% m.error %])</div>
+ <div><i class="fa fa-exclamation error"></i>Cannot retrieve pending jobs ([% m.error | html %])</div>
[% CASE 'cannot_view_job' %]
<div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
[% CASE %]
[% END %]
[% SWITCH m.code %]
[% CASE 'biblio_not_modified' %]
- 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 %].
+ 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 %].
[% CASE 'biblio_modified' %]
Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
[% END %]
[% END %]
[% SWITCH m.code %]
[% CASE 'authority_not_modified' %]
- 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 %].
+ 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 %].
[% CASE 'authority_modified' %]
Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% m.authid | uri %]">[% m.authid | html %]</a> has successfully been modified..
[% END %]
<div class="dialog message">
<i class="fa fa-info"></i>
[% IF pending_jobs.size > 0 %]
- There is [% pending_jobs.size %] pending jobs on the server: [% pending_jobs.join(', ') %].
+ There is [% pending_jobs.size | html %] pending jobs on the server: [% pending_jobs.join(', ') | html %].
[% ELSE %]
There is no pending jobs on the server.
[% END %]