From 5a976f685ac9d960b4ce0bc837b247050128d7a3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Feb 2020 13:26:53 +0100 Subject: [PATCH] Bug 22417: Try to display pending jobs - only work if worker not started ie. no subscription yet This needs to be fixed (if possible), or removed from the patchset Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Cook Signed-off-by: Marcel de Rooy --- admin/background_jobs.pl | 27 ++++++++++++++++++- .../prog/en/modules/admin/background_jobs.tt | 13 ++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl index 498891c80a..4eacc8c4d4 100755 --- a/admin/background_jobs.pl +++ b/admin/background_jobs.pl @@ -18,6 +18,8 @@ use Modern::Perl; use CGI qw ( -utf8 ); use JSON qw( decode_json ); +use Try::Tiny; + use C4::Context; use C4::Auth; use C4::Output; @@ -64,7 +66,30 @@ if ( $op eq 'cancel' ) { if ( $op eq 'list' ) { my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }}); - $template->param( jobs => $jobs, ); + my @pending_jobs; + try { + my $conn = Koha::BackgroundJob->connect; + my $job_type = 'batch_biblio_record_modification'; + $conn->subscribe({ destination => $job_type, ack => 'client' }); + my @frames; + while (my $frame = $conn->receive_frame({timeout => 1})) { + last unless $frame; + my $body = $frame->body; + my $args = decode_json($body); + push @pending_jobs, $args->{job_id}; + push @frames, $frame; + } + $conn->nack( { frame => $_ } ) for @frames; + $conn->disconnect; + } catch { + push @messages, { + type => 'error', + code => 'cannot_retrieve_jobs', + error => $_, + }; + }; + + $template->param( jobs => $jobs, pending_jobs => \@pending_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 d1cc6cec7d..2b04c0a844 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 @@ -21,8 +21,10 @@
[% FOR m IN messages %] -
+
[% SWITCH m.code %] + [% CASE 'cannot_retrieve_jobs' %] +
Cannot retrieve pending jobs ([% m.error %])
[% CASE %] [% m.code | html %] [% END %] @@ -109,6 +111,15 @@

Background jobs

+
+ + [% IF pending_jobs.size > 0 %] + There is [% pending_jobs.size %] pending jobs on the server: [% pending_jobs.join(', ') %]. + [% ELSE %] + There is no pending jobs on the server. + [% END %] +
+ [% IF jobs.count %] -- 2.20.1