From 8243a32e5bb8ae73635a760fc78ed62c39faff25 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 29 Apr 2022 14:52:59 +0100 Subject: [PATCH] Bug 30654: Processing outstanding jobs on startup This patch ensures jobs queued up in the database prior to worker startup are processed regardless as to whether you are using RabbitMQ or Database polling. --- misc/background_jobs_worker.pl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl index 0027a820e7..a2bd95697f 100755 --- a/misc/background_jobs_worker.pl +++ b/misc/background_jobs_worker.pl @@ -75,6 +75,9 @@ try { }; if ( $conn ) { + # process outstanding jobs on startup + process_outstanding; + # FIXME cf note in Koha::BackgroundJob about $namespace my $namespace = C4::Context->config('memcached_namespace'); for my $queue (@queues) { @@ -100,11 +103,7 @@ while (1) { $conn->ack( { frame => $frame } ); # FIXME depending on success? } else { - my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); - while ( my $job = $jobs->next ) { - my $args = decode_json($job->data); - process_job( $job, { job_id => $job->id, %$args } ); - } + process_outstanding; sleep 10; } } @@ -124,3 +123,12 @@ sub process_job { $job->process( $args ); exit; } + +sub process_outstanding { + my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); + while ( my $job = $jobs->next ) { + my $args = decode_json($job->data); + process_job( $job, { job_id => $job->id, %$args } ); + } + return 1; +} -- 2.20.1