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

(-)a/Koha/BackgroundJob.pm (-2 / +2 lines)
Lines 140-149 sub enqueue { Link Here
140
        my $encoded_args = Encode::encode_utf8( $json_args ); # FIXME We should better leave this to Net::Stomp?
140
        my $encoded_args = Encode::encode_utf8( $json_args ); # FIXME We should better leave this to Net::Stomp?
141
        my $destination = sprintf( "/queue/%s-%s", $namespace, $job_queue );
141
        my $destination = sprintf( "/queue/%s-%s", $namespace, $job_queue );
142
        $conn->send_with_receipt( { destination => $destination, body => $encoded_args, persistent => 'true' } )
142
        $conn->send_with_receipt( { destination => $destination, body => $encoded_args, persistent => 'true' } )
143
          or Koha::Exceptions::Exception->throw('Job has not been enqueued');
143
          or Koha::Exceptions::BackgroundJob->throw('Job has not been enqueued');
144
    } catch {
144
    } catch {
145
        $self->status('failed')->store;
145
        $self->status('failed')->store;
146
        if ( ref($_) eq 'Koha::Exceptions::Exception' ) {
146
        if ( ref($_) eq 'Koha::Exceptions::BackgroundJob' ) {
147
            $_->rethrow;
147
            $_->rethrow;
148
        } else {
148
        } else {
149
            warn sprintf "The job has not been sent to the message broker: (%s)", $_;
149
            warn sprintf "The job has not been sent to the message broker: (%s)", $_;
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-2 / +3 lines)
Lines 29-34 use Koha::DateUtils qw( dt_from_string ); Link Here
29
use Koha::SearchEngine::Indexer;
29
use Koha::SearchEngine::Indexer;
30
use Koha::Items;
30
use Koha::Items;
31
use Koha::UI::Table::Builder::Items;
31
use Koha::UI::Table::Builder::Items;
32
use Koha::Exceptions::BackgroundJob;
32
33
33
use base 'Koha::BackgroundJob';
34
use base 'Koha::BackgroundJob';
34
35
Lines 137-144 Enqueue the new job Link Here
137
sub enqueue {
138
sub enqueue {
138
    my ( $self, $args ) = @_;
139
    my ( $self, $args ) = @_;
139
140
140
    # TODO Raise exception instead
141
    Koha::Exceptions::BackgroundJob->throw('Job has not been enqueued')
141
    return unless exists $args->{record_ids};
142
        unless $args && exists $args->{record_ids};
142
143
143
    my @record_ids = @{ $args->{record_ids} };
144
    my @record_ids = @{ $args->{record_ids} };
144
145
(-)a/t/db_dependent/Koha/BackgroundJob.t (-2 / +14 lines)
Lines 26-31 use Test::Exception; Link Here
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::BackgroundJobs;
27
use Koha::BackgroundJobs;
28
use Koha::BackgroundJob::BatchUpdateItem;
28
use Koha::BackgroundJob::BatchUpdateItem;
29
use Koha::BackgroundJob::MARCImportCommitBatch;
29
30
30
use t::lib::Mocks;
31
use t::lib::Mocks;
31
use t::lib::Mocks::Logger;
32
use t::lib::Mocks::Logger;
Lines 69-78 subtest '_derived_class() tests' => sub { Link Here
69
70
70
subtest 'enqueue() tests' => sub {
71
subtest 'enqueue() tests' => sub {
71
72
72
    plan tests => 8;
73
    plan tests => 10;
73
74
74
    $schema->storage->txn_begin;
75
    $schema->storage->txn_begin;
75
76
77
    # Enqueue without args
78
    throws_ok { Koha::BackgroundJob::BatchUpdateItem->new->enqueue }
79
    'Koha::Exceptions::BackgroundJob',
80
        'Enqueue BatchUpdateItem without data throws exception';
81
82
    # The following test needs a mock to trigger the exception
83
    my $mock = Test::MockModule->new('Net::Stomp')->mock( 'send_with_receipt', 0 );
84
    throws_ok { Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue }
85
    'Koha::Exceptions::BackgroundJob',
86
        'Enqueue MARCImportCommitBatch with mock throws exception';
87
    $mock->unmock('send_with_receipt');
88
76
    # FIXME: This all feels we need to do it better...
89
    # FIXME: This all feels we need to do it better...
77
    my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } );
90
    my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } );
78
    my $job    = Koha::BackgroundJobs->find($job_id)->_derived_class;
91
    my $job    = Koha::BackgroundJobs->find($job_id)->_derived_class;
79
- 

Return to bug 35843