From 963701e184ce2c009c62d9b7e65b909e61d6057b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 5 Jan 2023 16:39:27 +0100 Subject: [PATCH] Bug 32393: Remove fork --- misc/background_jobs_worker.pl | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl index 89339d45eea..5c7908ee0a9 100755 --- a/misc/background_jobs_worker.pl +++ b/misc/background_jobs_worker.pl @@ -53,7 +53,6 @@ use Try::Tiny; use Pod::Usage; use Getopt::Long; -use Koha::Logger; use Koha::BackgroundJobs; my ( $help, @queues ); @@ -94,46 +93,37 @@ while (1) { next; # will reconnect automatically } + if ( $frame->command ne 'MESSAGE' ) { + warn "Frame is not a message we should process"; + warn $frame->body; + next; + } + my $job; + my $job_id; try { my $body = $frame->body; my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag. # FIXME This means we need to have create the DB entry before # It could work in a first step, but then we will want to handle job that will be created from the message received + $job_id = $args->{job_id}; $job = Koha::BackgroundJobs->find($args->{job_id}); - process_job( $job, $args ); + $job->process( $args ); } catch { Koha::Logger->get->warn(sprintf "Job and/or frame not processed - %s", $_); } finally { $job->status('failed')->store if $job && @_; $conn->ack( { frame => $frame } ); }; - } else { my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); while ( my $job = $jobs->next ) { my $args = $job->json->decode($job->data); - process_job( $job, { job_id => $job->id, %$args } ); + $job->process( { job_id => $job->id, %$args } ); } sleep 10; } } $conn->disconnect; - -sub process_job { - my ( $job, $args ) = @_; - - my $pid; - if ( $pid = fork ) { - wait; - return; - } - - die "fork failed!" unless defined $pid; - - $job->process( $args ); - - exit; -} -- 2.25.1