From 72b070c3f4c48ff7853eb7b2116d8473eb375b44 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 27 Mar 2017 17:25:33 -0300 Subject: [PATCH] Bug 15032: Try to fix background jobs - batch_record_modification.pl I do not really understand how behave this patch, sometimes it works, sometimes not. It would be good to get other people testing and reading it to try and understand what's happening. It may be a first step to fix our background jobs. The thing is that we cannot close STDOUT, Plack (CGI::Emulate::PSGI) is expecting it opened (search for 'seek'). If we close STDOUT and keep 'text/html' in the headers, it works almost correctly: but we got the JSON content + the headers printed by the child. With the redirect we a getting the right page when the job is finished. But sometimes we see the plain text content (with the JSON headers) + a 302 Any thoughts? --- debian/templates/apache-shared-intranet-plack.conf | 1 - tools/batch_record_modification.pl | 17 +++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/debian/templates/apache-shared-intranet-plack.conf b/debian/templates/apache-shared-intranet-plack.conf index 5ae8e07..e12f325 100644 --- a/debian/templates/apache-shared-intranet-plack.conf +++ b/debian/templates/apache-shared-intranet-plack.conf @@ -13,7 +13,6 @@ # don't break under plack/starman ProxyPass "/cgi-bin/koha/offline_circ/process_koc.pl" "!" ProxyPass "/cgi-bin/koha/tools/background-job-progress.pl" "!" - ProxyPass "/cgi-bin/koha/tools/batch_record_modification.pl" "!" ProxyPass "/cgi-bin/koha/tools/batchMod.pl" "!" ProxyPass "/cgi-bin/koha/tools/manage-marc-import.pl" "!" ProxyPass "/cgi-bin/koha/tools/stage-marc-import.pl" "!" diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 6ea0317..7c4a714 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -159,15 +159,11 @@ if ( $op eq 'form' ) { $job = C4::BackgroundJob->new( $sessionID, "FIXME", '/cgi-bin/koha/tools/batch_record_modification.pl', $job_size ); my $job_id = $job->id; if (my $pid = fork) { - $dbh->{InactiveDestroy} = 1; - my $reply = CGI->new(""); - print $reply->header(-type => 'text/html'); + print $reply->header(-type => 'application/json'); print '{"jobID":"' . $job_id . '"}'; exit 0; - } elsif (defined $pid) { - close STDOUT; - } else { + } elsif (not defined $pid) { warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job"; exit 0; } @@ -244,8 +240,13 @@ if ( $op eq 'form' ) { } if ($runinbackground) { - $job->finish if defined $job; - } else { + if ( $job ) { + $job->finish; + print $input->redirect('/cgi-bin/koha/tools/background.pl?just_a_param=1'); + } + } + else { + # FIXME Do not think this is reach $template->param( view => 'report', report => $report, -- 2.9.3