Bug 40846: Improve handling of ignored records
Currently, a job is marked failed if there are no records added or updated. We should take ignored records into account. Additionally, I mark the job failed when the number of records processed doesn't equal the number of records in the batch. To test: 1) Export some records from your Koha, include some with items 2) Stage and import those records into Koha, matching on biblionumber, ignoring matcheds, updating items 3) View the import job, it is marked failed 4) View the batch, all records imported 5) Apply patch, restart all 6) Stage/import as before 7) Job is now marked finished 8) Records imported as before Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
f39a2118cd
commit
aef17e613d
|
|
@ -84,11 +84,10 @@ sub process {
|
|||
progress_callback => sub { my $job_progress = shift; $self->progress($job_progress)->store },
|
||||
}
|
||||
);
|
||||
my $count = $num_added + $num_updated;
|
||||
if ($count) {
|
||||
$self->set( { progress => $count, size => $count } );
|
||||
} else { # TODO Refine later
|
||||
$self->set( { progress => 0, status => 'failed' } );
|
||||
my $count = $num_added + $num_updated + $num_ignored;
|
||||
$self->set( { progress => $count } );
|
||||
if ( $count != $size ) {
|
||||
$self->set( { status => 'failed' } );
|
||||
}
|
||||
} catch {
|
||||
warn $_;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::MockModule;
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 2;
|
||||
use Test::More tests => 3;
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::BackgroundJobs;
|
||||
|
|
@ -51,3 +52,41 @@ subtest 'enqueue() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'process() tests' => sub {
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $batch_return = [];
|
||||
my $output_module = Test::MockModule->new('Koha::BackgroundJob::MARCImportCommitBatch');
|
||||
$output_module->mock(
|
||||
'BatchCommitRecords',
|
||||
sub {
|
||||
return @{$batch_return};
|
||||
}
|
||||
);
|
||||
my $import_batch = $builder->build_object( { class => 'Koha::ImportBatches' } );
|
||||
|
||||
# Add two records
|
||||
$builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } );
|
||||
$builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } );
|
||||
|
||||
my $job_id = Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue( { import_batch_id => $import_batch->id } );
|
||||
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
|
||||
|
||||
@{$batch_return} = ( 0, 0, 0, 0, 0, 2 );
|
||||
$job->process( { import_batch_id => $import_batch->id } );
|
||||
$job->discard_changes;
|
||||
is( $job->status, 'finished', 'A job where all records are ignored is a success' );
|
||||
|
||||
$job->status('new')->store;
|
||||
@{$batch_return} = ( 1, 1, 0, 0, 0, 1 );
|
||||
$job->process( { import_batch_id => $import_batch->id } );
|
||||
$job->discard_changes;
|
||||
is( $job->status, 'failed', 'A job where the record counts do not match is failed' );
|
||||
is( $job->size, '2', 'Size is based on number of records' );
|
||||
is( $job->progress, '3', 'Progress is the total number of records processed, including added/updated/ignored' );
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue