From b54c854d248f3c320f20d59224272d1631e27b0c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 21 May 2024 10:04:17 -0300 Subject: [PATCH] Bug 36901: Add logging for uncaught exceptions in background job classes This patch adds logging of unhandled exceptions that could occur. This is happening on busy production sites right now. This is also useful for plugin jobs that might not be 100% following the guidelines and would benefit from this. But as the [DO NOT PUSH] patch highlights, this is something we really want to have on our current codebase, as a database connection drop might make us reach that `catch` block we are adding logging to on this patch. To test: 1. Apply the [DO NOT PUSH] patch 2. Run: $ ktd --shell k$ restart_all ; tail -f /var/log/koha/kohadev/worker*.log 3. Pick a valid barcode on the staff UI 4. Use the 'Batch delete items' tool in the cataloguing section 5. Start the job for deleting the item => FAIL: The item got deleted, but the job marked as failed and no logs about the reasons 6. Apply this patch and repeat 2-5 => SUCCESS: Same scenario but there's a log with the error message 7. Sign off :-D Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- misc/workers/background_jobs_worker.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index bfe126f099..e2472d0fcd 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -202,8 +202,10 @@ $pm->wait_all_children; sub process_job { my ( $job, $args ) = @_; try { - $job->process( $args ); + $job->process($args); } catch { + Koha::Logger->get( { interface => 'worker' } ) + ->warn( sprintf "Uncaught exception processing job id=%s: %s", $job->id, $_ ); $job->status('failed')->store; }; } -- 2.39.5