Bug 33962: Remove background job from process koc

The last occurrence of C4::BackgroundJob is in process_koc.pl that is used to upload a file.
Added by bug 2608 (15 years ago), I think it does not longer make sense as networks are faster, and we should not expect big koc files to be uploaded.
If there are complains we will move it to Koha::BackgroundJob.

Test plan:
Upload a koc file, enqueue the operations and confirm that everything is
working correctly

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-06-08 17:19:55 +02:00 committed by Tomas Cohen Arazi
parent 9f4e9f451b
commit 7a417aa33f
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
3 changed files with 7 additions and 73 deletions

View File

@ -11,7 +11,6 @@
# FIXME: These scripts should be fixed so they
# 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/export.pl" "!"
ProxyPass "/cgi-bin/koha/tools/upload-cover-image.pl" "!"

View File

@ -81,17 +81,13 @@
<form action="enqueue_koc.pl" id="processfile" method="post" enctype="multipart/form-data">
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
<input type="hidden" name="action" value="add_to_queue" />
<input type="submit" value="Add to offline circulation queue" id="queueformsubmit" />
</form>
<form action="process_koc.pl" id="enqueuefile" method="post" enctype="multipart/form-data">
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
<input type="hidden" name="runinbackground" id="runinbackground" value="" />
<input type="hidden" name="completedJobID" id="completedJobID" value="" />
<!-- <input type="submit" value="Apply directly" id="mainformsubmit" /> -->
<!-- FIXME: Job freezes when submitted, disabling button as a temporary mitigation -->
<div id="jobstatus" style="display:none">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
<div id="jobfailed" style="display:none"></div>
</form>
[% END %]
@ -100,7 +96,6 @@
</div>
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/background-job-progressbar.js") | $raw %]
[% Asset.js("js/file-upload.js") | $raw %]
<script>
var xhr;
@ -128,7 +123,7 @@
$("#fileuploadstatus").show();
$("form#processfile #uploadedfileid").val('');
$("form#enqueuefile #uploadedfileid").val('');
xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
xhr = AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
}
function cbUpload( status, fileid, errors ) {
@ -154,11 +149,7 @@
if (f.uploadedfileid.value == '') {
alert(_("Please upload a file first."));
} else {
$("#fileuploadstatus").hide();
$("#fileuploadform").slideUp();
$("#mainformsubmit").prop('disabled',true);
$("#queueformsubmit").prop('disabled',true);
return submitBackgroundJob(f);
return f.submit();
}
return false;
}

View File

@ -25,12 +25,8 @@ use CGI qw ( -utf8 );
use C4::Output qw( output_html_with_http_headers );
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Accounts;
use C4::Circulation qw( barcodedecode AddRenewal AddIssue MarkIssueReturned );
use C4::Items qw( ModDateLastSeen );
use C4::Members;
use C4::Stats;
use C4::BackgroundJob;
use Koha::UploadedFiles;
use Koha::Account;
use Koha::Checkouts;
@ -54,20 +50,15 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
my $fileID=$query->param('uploadedfileid');
my $runinbackground = $query->param('runinbackground');
my $completedJobID = $query->param('completedJobID');
my $op = $query->param('op') || q{};
my %cookies = CGI::Cookie->fetch();
my $sessionID = $cookies{'CGISESSID'}->value;
## 'Local' globals.
our $dbh = C4::Context->dbh();
our @output = (); ## For storing messages to be displayed to the user
if ($completedJobID) {
my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
my $results = $job->results();
if ( $op eq 'add_to_queue' ) {
$template->param(transactions_loaded => 1);
$template->param(messages => $results->{results});
} elsif ($fileID) {
my $upload = Koha::UploadedFiles->find( $fileID );
my $fh = $upload? $upload->file_handle: undef;
@ -75,45 +66,6 @@ if ($completedJobID) {
my @input_lines = $fh? <$fh>: ();
$fh->close if $fh;
my $job = undef;
if ($runinbackground) {
my $job_size = scalar(@input_lines);
$job = C4::BackgroundJob->new($sessionID, $filename, '/cgi-bin/koha/offline_circ/process_koc.pl', $job_size);
my $jobID = $job->id();
# fork off
if (my $pid = fork) {
# parent
# return job ID as JSON
# prevent parent exiting from
# destroying the kid's database handle
# FIXME: according to DBI doc, this may not work for Oracle
$dbh->{InactiveDestroy} = 1;
my $reply = CGI->new("");
print $reply->header(-type => 'text/html');
print '{"jobID":"' . $jobID . '"}';
exit 0;
} elsif (defined $pid) {
# child
# close STDOUT to signal to Apache that
# we're now running in the background
close STDOUT;
close STDERR;
} else {
# fork failed, so exit immediately
# fork failed, so exit immediately
warn "fork failed while attempting to run offline_circ/process_koc.pl as a background job";
exit 0;
}
# if we get here, we're a child that has detached
# itself from Apache
}
my $header_line = shift @input_lines;
my $file_info = parse_header_line($header_line);
if ($file_info->{'Version'} ne $FILE_VERSION) {
@ -143,18 +95,10 @@ if ($completedJobID) {
} else {
warn "unknown command: '$command_line->{command}' not processed";
}
if ($runinbackground) {
$job->progress($i);
}
}
if ($runinbackground) {
$job->finish({ results => \@output }) if defined($job);
} else {
$template->param(transactions_loaded => 1);
$template->param(messages => \@output);
}
$template->param(transactions_loaded => 1);
$template->param(messages => \@output);
}
output_html_with_http_headers $query, $cookie, $template->output;