From 8deefd6a2ac8d15e6ce935ad9dd867c1994dd584 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 26 Feb 2024 09:33:00 +0000 Subject: [PATCH] Bug 36484: Fetch all outstanding (New) update_elastic_index background jobs upon starting koha-es-indexer Test plan: 1. Ensure your Koha instance is using Elasticsearch 2. Apply patches 3. sudo koha-es-indexer --stop 4. Add a new biblio record in your Koha instance 5. Query your database and ensure there is one outstanding update_elastic_index job in background_jobs: SELECT * FROM background_jobs WHERE type = 'update_elastic_index' AND status = 'new'; 6. Start services: sud service koha-common start 7. Repeat step 5 and observe the outstanding job is not returned by the query - that is because it has been processed. Sponsored-by: Toi Ohomai Institute of Technology, New Zealand --- misc/workers/es_indexer_daemon.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/misc/workers/es_indexer_daemon.pl b/misc/workers/es_indexer_daemon.pl index 9e900b7195c..0deefac989a 100755 --- a/misc/workers/es_indexer_daemon.pl +++ b/misc/workers/es_indexer_daemon.pl @@ -91,6 +91,7 @@ try { }; if ( $conn ) { + process_outstanding(); # FIXME cf note in Koha::BackgroundJob about $namespace my $namespace = C4::Context->config('memcached_namespace'); $conn->subscribe( @@ -132,7 +133,6 @@ while (1) { } my $job = Koha::BackgroundJobs->find( $args->{job_id} ); - if ( $job && $job->status ne 'new' ) { Koha::Logger->get( { interface => 'worker' } ) ->warn( sprintf "Job %s has wrong status %s", $args->{job_id}, $job->status ); @@ -238,3 +238,11 @@ sub commit { ended_on => \'NOW()', }); } + +sub process_outstanding { + my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => 'elastic_index' }); + while ( my $job = $jobs->next ) { + commit($job); + } + return 1; +} -- 2.30.2