@@ -, +, @@
---
Koha/BackgroundJob.pm | 38 +++++++++++++---------
.../en/modules/tools/batch_record_modification.tt | 2 ++
tools/batch_record_modification.pl | 32 +++++++++++-------
3 files changed, 46 insertions(+), 26 deletions(-)
--- a/Koha/BackgroundJob.pm
+++ a/Koha/BackgroundJob.pm
@@ -29,21 +29,29 @@ sub enqueue {
my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls
my $json_args = encode_json $job_args;
- $self->set({
- status => 'new',
- type => $job_type,
- size => $job_size,
- data => $json_args,
- enqueued_on => dt_from_string,
- borrowernumber => $borrowernumber,
- })->store;
-
- my $job_id = $self->id;
- $job_args->{job_id} = $job_id;
- $json_args = encode_json $job_args,
-
- my $conn = $self->connect;
- $conn->send({destination => $job_type, body => $json_args});
+ my $job_id;
+ $self->_result->result_source->schema->txn_do(
+ sub {
+ $self->set(
+ {
+ status => 'new',
+ type => $job_type,
+ size => $job_size,
+ data => $json_args,
+ enqueued_on => dt_from_string,
+ borrowernumber => $borrowernumber,
+ }
+ )->store;
+
+ $job_id = $self->id;
+ $job_args->{job_id} = $job_id;
+ $json_args = encode_json $job_args;
+
+ my $conn = $self->connect;
+ $conn->send_with_receipt( { destination => $job_type, body => $json_args } )
+ or Koha::Exception->throw('Job has not been enqueued');
+ }
+ );
return $job_id;
}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt
@@ -46,6 +46,8 @@
Authority record [% message.authid | html %] has not been modified. An error occurred on modifying it.
[% ELSIF message.code == 'authority_modified' %]
Bibliographic record [% message.authid | html %] has successfully been modified.
+ [% ELSIF message.code == 'cannot_enqueue_job' %]
+ Cannot enqueue this job.
[% END %]
[% IF message.error %]
(The error was: [% message.error | html %]. See the Koha logfile for more information).
--- a/tools/batch_record_modification.pl
+++ a/tools/batch_record_modification.pl
@@ -23,6 +23,7 @@ use Modern::Perl;
use CGI;
use List::MoreUtils qw( uniq );
use JSON qw( encode_json );
+use Try::Tiny;
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
@@ -150,17 +151,26 @@ if ( $op eq 'form' ) {
# We want to modify selected records!
my @record_ids = $input->multi_param('record_id');
- my $job_id = Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue(
- {
- mmtid => $mmtid,
- record_type => $recordtype,
- record_ids => \@record_ids,
- }
- );
- $template->param(
- view => 'enqueued',
- job_id => $job_id,
- );
+ try {
+ my $job_id = Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue(
+ {
+ mmtid => $mmtid,
+ record_type => $recordtype,
+ record_ids => \@record_ids,
+ }
+ );
+ $template->param(
+ view => 'enqueued',
+ job_id => $job_id,
+ );
+ } catch {
+ push @messages, {
+ type => 'error',
+ code => 'cannot_enqueue_job',
+ error => $_,
+ };
+ $template->param( view => 'errors' );
+ };
}
$template->param(
--