From 1985eac9a6e912b8fe3cf3efc9ee11f151071630 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 17 Mar 2023 14:22:24 +0000 Subject: [PATCH] Bug 32594: POC --- Koha/BackgroundJobs.pm | 21 +++++++++++++++++++++ misc/workers/es_indexer_daemon.pl | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm index 48afbf68fa..f3f6e39e77 100644 --- a/Koha/BackgroundJobs.pm +++ b/Koha/BackgroundJobs.pm @@ -72,6 +72,27 @@ sub filter_by_current { ); } +=head3 finish + + my $jobs->finish; + +Finishes multiple jobs, assumes you have handled success or failure. + +=cut + +sub finish { + my ($self) = @_; + + while( my $job = $self->next ){ + $job->update({ + progress => $job->size(), + status => 'finished', + ended_on =>\'NOW()' + },{ no_triggers => 1}); + } + +} + =head2 Internal methods =head3 _type diff --git a/misc/workers/es_indexer_daemon.pl b/misc/workers/es_indexer_daemon.pl index b871acefcf..4075bb6607 100755 --- a/misc/workers/es_indexer_daemon.pl +++ b/misc/workers/es_indexer_daemon.pl @@ -182,5 +182,5 @@ sub commit { }; } - Koha::BackgroundJobs->search( { id => [ map { $_->id } @jobs ] } )->update( { status => 'finished', progress => 1 }, { no_triggers => 1 } ); + Koha::BackgroundJobs->search( { id => [ map { $_->id } @jobs ] })->finish(); } -- 2.30.2