Bugzilla – Attachment 109331 Details for
Bug 22417
Add a task queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22417: Handle errors
Bug-22417-Handle-errors.patch (text/plain), 4.93 KB, created by
Marcel de Rooy
on 2020-08-31 08:26:06 UTC
(
hide
)
Description:
Bug 22417: Handle errors
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2020-08-31 08:26:06 UTC
Size:
4.93 KB
patch
obsolete
>From b546b99162d8f58b4c389bab6a8ef54abe301793 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 20 Feb 2020 12:23:07 +0100 >Subject: [PATCH] Bug 22417: Handle errors >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Cook <dcook@prosentient.com.au> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > 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(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 5aa2cd67a8..caf4d300f5 100644 >--- a/Koha/BackgroundJob.pm >+++ b/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; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >index dc1d04c649..1c09747848 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >@@ -46,6 +46,8 @@ > Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has not been modified. An error occurred on modifying it. > [% ELSIF message.code == 'authority_modified' %] > Bibliographic record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> 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). >diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl >index 23d54de053..5b645993ec 100755 >--- a/tools/batch_record_modification.pl >+++ b/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( >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22417
:
105542
|
105543
|
107385
|
107386
|
107387
|
107388
|
107389
|
107390
|
107391
|
107392
|
107393
|
107394
|
107395
|
107396
|
107397
|
107398
|
107399
|
107400
|
107401
|
107402
|
107403
|
107404
|
107405
|
107406
|
107481
|
107482
|
107682
|
108023
|
108024
|
108025
|
108026
|
108027
|
108028
|
108029
|
108030
|
108031
|
108032
|
108033
|
108034
|
108035
|
108036
|
108037
|
108038
|
108039
|
108040
|
108041
|
108042
|
108043
|
108044
|
108045
|
108046
|
108047
|
109270
|
109271
|
109319
|
109320
|
109321
|
109322
|
109323
|
109324
|
109325
|
109326
|
109327
|
109328
|
109329
|
109330
|
109331
|
109332
|
109333
|
109334
|
109335
|
109336
|
109337
|
109338
|
109339
|
109340
|
109341
|
109342
|
109343
|
109344
|
109345
|
109350
|
109351
|
109355
|
109390
|
109391
|
109392
|
109393
|
109394
|
109395
|
109396
|
109397
|
109398
|
109399
|
109400
|
109401
|
109402
|
109403
|
109404
|
109405
|
109406
|
109407
|
109408
|
109409
|
109410
|
109411
|
109412
|
109413
|
109414
|
109415
|
109416
|
109417
|
109418
|
109474
|
109475
|
109476
|
109477
|
110150
|
111091
|
111092
|
111093
|
111094
|
111095
|
111096
|
111097
|
111098
|
111099
|
111100
|
111101
|
111102
|
111103
|
111104
|
111105
|
111106
|
111107
|
111108
|
111109
|
111110
|
111111
|
111112
|
111113
|
111114
|
111115
|
111116
|
111117
|
111118
|
111119
|
111120
|
111121
|
111238
|
111239
|
111245