+ my $filename = $uploaded_file->name();
+ my $job = undef;
+ my $staging_callback = sub { };
+ my $matching_callback = sub { };
+ if ($runinbackground) {
+ my $job_size = () = $marcrecord =~ /\035/g;
+ # if we're matching, job size is doubled
+ $job_size *= 2 if ($matcher_id ne "");
+ $job = C4::BackgroundJob->new($sessionID, $filename, $ENV{'SCRIPT_NAME'}, $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
+ warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
+ exit 0;
+ }
+
+ # if we get here, we're a child that has detached
+ # itself from Apache
+ $staging_callback = staging_progress_callback($job, $dbh);
+ $matching_callback = matching_progress_callback($job, $dbh);
+
+ }