Bugzilla – Attachment 108031 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: Add the ability to cancel a job
Bug-22417-Add-the-ability-to-cancel-a-job.patch (text/plain), 6.35 KB, created by
David Cook
on 2020-08-11 08:17:52 UTC
(
hide
)
Description:
Bug 22417: Add the ability to cancel a job
Filename:
MIME Type:
Creator:
David Cook
Created:
2020-08-11 08:17:52 UTC
Size:
6.35 KB
patch
obsolete
>From 3d0e2986815a299fd469cdbbace37e7d746af167 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 27 Feb 2019 10:34:42 -0300 >Subject: [PATCH] Bug 22417: Add the ability to cancel a job > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Cook <dcook@prosentient.com.au> >--- > Koha/BackgroundJob.pm | 6 ++++++ > Koha/BackgroundJob/BatchUpdateBiblio.pm | 19 ++++++++++++------- > admin/background_jobs.pl | 8 ++++++++ > .../prog/en/modules/admin/background_jobs.tt | 11 ++++++++--- > new_koha_job.pl | 3 --- > 5 files changed, 34 insertions(+), 13 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 6eab98c6b5..bc22b19390 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -3,6 +3,8 @@ package Koha::BackgroundJob; > use Modern::Perl; > use JSON qw( encode_json decode_json ); > use Carp qw( croak ); >+use Net::RabbitFoot; >+ > use C4::Context; > use Koha::DateUtils qw( dt_from_string ); > use Koha::BackgroundJobs; >@@ -81,6 +83,10 @@ sub report { > return $data_dump->{report}; > } > >+sub cancel { >+ my ( $self ) = @_; >+ $self->status('cancelled')->store; >+} > > sub _type { > return 'BackgroundJob'; >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index 4e205bd187..990b34902a 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -14,10 +14,13 @@ sub process { > > my $job_type = $args->{job_type}; > >- return unless exists $args->{job_id}; >- > my $job = Koha::BackgroundJobs->find( $args->{job_id} ); > >+ if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) { >+ $channel->ack; >+ return; >+ } >+ > my $job_progress = 0; > $job->started_on(dt_from_string) > ->progress($job_progress) >@@ -29,14 +32,16 @@ sub process { > my @record_ids = @{ $args->{record_ids} }; > > my $report = { >- total_records => 0, >+ total_records => scalar @record_ids, > total_success => 0, > }; > my @messages; > my $dbh = C4::Context->dbh; > $dbh->{RaiseError} = 1; > RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { >- $report->{total_records}++; >+ >+ last if $job->get_from_storage->status eq 'cancelled'; >+ > next unless $biblionumber; > > # Modify the biblio >@@ -69,9 +74,9 @@ sub process { > $job_data->{report} = $report; > > $job->ended_on(dt_from_string) >- ->status('finished') >- ->data(encode_json $job_data) >- ->store; >+ ->data(encode_json $job_data); >+ $job->status('finished') if $job->status ne 'cancelled'; >+ $job->store; > $channel->ack(); # FIXME Is that ok even on failure? > } > >diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl >index 2b4ca03dbf..498891c80a 100755 >--- a/admin/background_jobs.pl >+++ b/admin/background_jobs.pl >@@ -51,9 +51,17 @@ if ( $op eq 'view' ) { > } else { > $op = 'list'; > } >+} > >+if ( $op eq 'cancel' ) { >+ my $id = $input->param('id'); >+ if ( my $job = Koha::BackgroundJobs->find($id) ) { # FIXME Make sure logged in user can cancel this job >+ $job->cancel; >+ } >+ $op = 'list'; > } > >+ > if ( $op eq 'list' ) { > my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }}); > $template->param( jobs => $jobs, ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >index 098b7a3239..8009711e92 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >@@ -52,7 +52,9 @@ > </div> > [% ELSE %] > <div class="dialog message"> >- [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> >+ [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. >+ [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] >+ <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> > </div> > [% END %] > [% END %] >@@ -137,8 +139,11 @@ > <td>[% job.started_on| html %]</td> > <td>[% job.ended_on| html %]</td> > <td class="actions"> >- <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=delete_confirm&id=[% job.id | html %]"><i class="fa fa-pencil"></i> Delete</a> >- <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a> >+ <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a> >+ [% IF job.status == 'new' || job.status == 'started' %] >+ <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&id=[% job.id | html %]"><i class="fa fa-pencil"></i> Cancel</a> >+ [% END %] >+ <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a> > </td> > </tr> > [% END %] >diff --git a/new_koha_job.pl b/new_koha_job.pl >index b29aa82d94..425f412c2c 100644 >--- a/new_koha_job.pl >+++ b/new_koha_job.pl >@@ -3,9 +3,6 @@ > use Modern::Perl; > use C4::Context; > use Koha::BackgroundJob::BatchUpdateBiblio; >-use Koha::BackgroundJob; >- >-use Net::RabbitFoot; > > my $mmtid = 1; > my $record_type = 'biblio'; >-- >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