1 package t::lib::Koha::BackgroundJob::BatchTest;
3 # This file is part of Koha.
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.
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.
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>.
19 use JSON qw( decode_json encode_json );
21 use Koha::BackgroundJobs;
22 use Koha::DateUtils qw( dt_from_string );
24 use base 'Koha::BackgroundJob';
31 my ( $self, $args ) = @_;
33 my $job = Koha::BackgroundJobs->find( $args->{job_id} );
35 if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
40 $job->started_on(dt_from_string)
41 ->progress($job_progress)
46 total_records => $job->size,
50 for my $i ( 0 .. $job->size - 1 ) {
52 last if $job->get_from_storage->status eq 'cancelled';
58 $report->{total_success}++;
59 $job->progress( ++$job_progress )->store;
62 my $job_data = decode_json $job->data;
63 $job_data->{messages} = \@messages;
64 $job_data->{report} = $report;
66 $job->ended_on(dt_from_string)
67 ->data(encode_json $job_data);
68 $job->status('finished') if $job->status ne 'cancelled';
73 my ( $self, $args) = @_;
75 $self->SUPER::enqueue({
76 job_size => $args->{size},
77 job_args => {a => $args->{a}, b => $args->{b}}