Bug 35843: Correct invalid exception
Test plan: Run background job tests. Especially the changed one. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Magnus Enger <magnus@libriotech.no> All test pass when running this: prove t/db_dependent/Koha/BackgroundJobs* Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
ff2318865e
commit
291268f318
3 changed files with 19 additions and 5 deletions
|
@ -140,10 +140,10 @@ sub enqueue {
|
||||||
my $encoded_args = Encode::encode_utf8( $json_args ); # FIXME We should better leave this to Net::Stomp?
|
my $encoded_args = Encode::encode_utf8( $json_args ); # FIXME We should better leave this to Net::Stomp?
|
||||||
my $destination = sprintf( "/queue/%s-%s", $namespace, $job_queue );
|
my $destination = sprintf( "/queue/%s-%s", $namespace, $job_queue );
|
||||||
$conn->send_with_receipt( { destination => $destination, body => $encoded_args, persistent => 'true' } )
|
$conn->send_with_receipt( { destination => $destination, body => $encoded_args, persistent => 'true' } )
|
||||||
or Koha::Exceptions::Exception->throw('Job has not been enqueued');
|
or Koha::Exceptions::BackgroundJob->throw('Job has not been enqueued');
|
||||||
} catch {
|
} catch {
|
||||||
$self->status('failed')->store;
|
$self->status('failed')->store;
|
||||||
if ( ref($_) eq 'Koha::Exceptions::Exception' ) {
|
if ( ref($_) eq 'Koha::Exceptions::BackgroundJob' ) {
|
||||||
$_->rethrow;
|
$_->rethrow;
|
||||||
} else {
|
} else {
|
||||||
warn sprintf "The job has not been sent to the message broker: (%s)", $_;
|
warn sprintf "The job has not been sent to the message broker: (%s)", $_;
|
||||||
|
|
|
@ -29,6 +29,7 @@ use Koha::DateUtils qw( dt_from_string );
|
||||||
use Koha::SearchEngine::Indexer;
|
use Koha::SearchEngine::Indexer;
|
||||||
use Koha::Items;
|
use Koha::Items;
|
||||||
use Koha::UI::Table::Builder::Items;
|
use Koha::UI::Table::Builder::Items;
|
||||||
|
use Koha::Exceptions::BackgroundJob;
|
||||||
|
|
||||||
use base 'Koha::BackgroundJob';
|
use base 'Koha::BackgroundJob';
|
||||||
|
|
||||||
|
@ -137,8 +138,8 @@ Enqueue the new job
|
||||||
sub enqueue {
|
sub enqueue {
|
||||||
my ( $self, $args ) = @_;
|
my ( $self, $args ) = @_;
|
||||||
|
|
||||||
# TODO Raise exception instead
|
Koha::Exceptions::BackgroundJob->throw('Job has not been enqueued')
|
||||||
return unless exists $args->{record_ids};
|
unless $args && exists $args->{record_ids};
|
||||||
|
|
||||||
my @record_ids = @{ $args->{record_ids} };
|
my @record_ids = @{ $args->{record_ids} };
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ use Test::Exception;
|
||||||
use Koha::Database;
|
use Koha::Database;
|
||||||
use Koha::BackgroundJobs;
|
use Koha::BackgroundJobs;
|
||||||
use Koha::BackgroundJob::BatchUpdateItem;
|
use Koha::BackgroundJob::BatchUpdateItem;
|
||||||
|
use Koha::BackgroundJob::MARCImportCommitBatch;
|
||||||
|
|
||||||
use t::lib::Mocks;
|
use t::lib::Mocks;
|
||||||
use t::lib::Mocks::Logger;
|
use t::lib::Mocks::Logger;
|
||||||
|
@ -69,10 +70,22 @@ subtest '_derived_class() tests' => sub {
|
||||||
|
|
||||||
subtest 'enqueue() tests' => sub {
|
subtest 'enqueue() tests' => sub {
|
||||||
|
|
||||||
plan tests => 8;
|
plan tests => 10;
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
|
# Enqueue without args
|
||||||
|
throws_ok { Koha::BackgroundJob::BatchUpdateItem->new->enqueue }
|
||||||
|
'Koha::Exceptions::BackgroundJob',
|
||||||
|
'Enqueue BatchUpdateItem without data throws exception';
|
||||||
|
|
||||||
|
# The following test needs a mock to trigger the exception
|
||||||
|
my $mock = Test::MockModule->new('Net::Stomp')->mock( 'send_with_receipt', 0 );
|
||||||
|
throws_ok { Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue }
|
||||||
|
'Koha::Exceptions::BackgroundJob',
|
||||||
|
'Enqueue MARCImportCommitBatch with mock throws exception';
|
||||||
|
$mock->unmock('send_with_receipt');
|
||||||
|
|
||||||
# FIXME: This all feels we need to do it better...
|
# FIXME: This all feels we need to do it better...
|
||||||
my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } );
|
my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } );
|
||||||
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
|
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
|
||||||
|
|
Loading…
Reference in a new issue