From ae9d3b0477bc3b5dede11fef6ea9a0d546602467 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 7 Jun 2022 11:08:32 +0100 Subject: [PATCH] Bug 30462: [22.05.x] Separate Queued and Complete jobs This patch updates the background jobs management page to display queued and completed jobs in their own tabs on the page. JD Amended patch: Fix QA failures: FAIL koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt FAIL forbidden patterns forbidden pattern: trailing space char (line 158) forbidden pattern: trailing space char (line 256) Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Bug 30462: (follow-up) Limit completed to 60 minutes This follow-up reduces the completed jobs list to only those jobs completed within the last 60 minutes. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Bug 30462: Remove 'Ended' column for current jobs This column will always be empty Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Bug 30462: Fix display of the complete jobs We want to display the jobs terminated in the last hour, not today. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Bug 30462: (QA follow-up) Tab name change Signed-off-by: Tomas Cohen Arazi Signed-off-by: Lucas Gass --- admin/background_jobs.pl | 29 +++- .../prog/en/modules/admin/background_jobs.tt | 149 +++++++++++++----- 2 files changed, 132 insertions(+), 46 deletions(-) diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl index a4b7b90c0a..761c09d069 100755 --- a/admin/background_jobs.pl +++ b/admin/background_jobs.pl @@ -19,6 +19,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Context; +use Koha::DateUtils qw( dt_from_string ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); @@ -78,15 +79,35 @@ if ( $op eq 'cancel' ) { if ( $op eq 'list' ) { - my $jobs = + my $queued_jobs = $can_manage_background_jobs - ? Koha::BackgroundJobs->search( {}, + ? Koha::BackgroundJobs->search( { ended_on => undef }, { order_by => { -desc => 'enqueued_on' } } ) : Koha::BackgroundJobs->search( - { borrowernumber => $logged_in_user->borrowernumber }, + { borrowernumber => $logged_in_user->borrowernumber, ended_on => undef }, { order_by => { -desc => 'enqueued_on' } } ); - $template->param( jobs => $jobs ); + $template->param( queued => $queued_jobs ); + + my $ended_since = dt_from_string->subtract( minutes => '60' ); + my $dtf = Koha::Database->new->schema->storage->datetime_parser; + + my $complete_jobs = + $can_manage_background_jobs + ? Koha::BackgroundJobs->search( + { + ended_on => { '>=' => $dtf->format_datetime($ended_since) } + }, + { order_by => { -desc => 'enqueued_on' } } + ) + : Koha::BackgroundJobs->search( + { + borrowernumber => $logged_in_user->borrowernumber, + ended_on => { '>=' => $dtf->format_datetime($ended_since) } + }, + { order_by => { -desc => 'enqueued_on' } } + ); + $template->param( complete => $complete_jobs ); } $template->param( 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 ab1cd65cba..0fafb30da4 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 @@ -156,49 +156,106 @@

Background jobs

- [% IF jobs.count %] - - - - - - - - - - - - - - - [% FOREACH job IN jobs %] - - - - - - - - - - +
+ + +
+
+ [% IF queued.count %] +
Job IDStatusProgressTypeQueuedStartedEndedActions
[% job.id | html %] - [% PROCESS show_job_status %] - [% job.progress || 0 | html %] / [% job.size | html %] - [% PROCESS show_job_type job_type => job.type %] - [% job.enqueued_on | $KohaDates with_hours = 1 %][% job.started_on| $KohaDates with_hours = 1 %][% job.ended_on| $KohaDates with_hours = 1 %] - View - [% IF job.status == 'new' || job.status == 'started' %] - Cancel - [% END %] -
+ + + + + + + + + + + + + [% FOREACH job IN queued %] + + + + + + + + + + [% END %] + +
Job IDStatusProgressTypeQueuedStartedActions
[% job.id | html %] + [% PROCESS show_job_status %] + [% job.progress || 0 | html %] / [% job.size | html %] + [% PROCESS show_job_type job_type => job.type %] + [% job.enqueued_on | $KohaDates with_hours = 1 %][% job.started_on| $KohaDates with_hours = 1 %] + View + [% IF job.status == 'new' || job.status == 'started' %] + Cancel + [% END %] +
+ [% ELSE %] +
+ There are no queued background jobs yet. +
[% END %] - - - [% ELSE %] -
- There are no background jobs yet. +
+ +
+ [% IF complete.count %] +

Jobs completed in the last 60 minutes.

+ + + + + + + + + + + + + + + [% FOREACH job IN complete %] + + + + + + + + + + + [% END %] + +
Job IDStatusProgressTypeQueuedStartedEndedActions
[% job.id | html %] + [% PROCESS show_job_status %] + [% job.progress || 0 | html %] / [% job.size | html %] + [% PROCESS show_job_type job_type => job.type %] + [% job.enqueued_on | $KohaDates with_hours = 1 %][% job.started_on| $KohaDates with_hours = 1 %][% job.ended_on| $KohaDates with_hours = 1 %] + View + [% IF job.status == 'new' || job.status == 'started' %] + Cancel + [% END %] +
+ [% ELSE %] +
+ There were no completed background jobs completed in the last 60 minutes. +
+ [% END %] +
- [% END %] + + [% END %] @@ -216,7 +273,7 @@ [% INCLUDE 'datatables.inc' %] [% IF op == 'view' %] -- 2.39.5