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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit b54c854d24)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2024-05-21 10:04:17 -03:00 committed by Lucas Gass
parent f49de36e81
commit cc8f03cf2b
1 changed files with 3 additions and 1 deletions

View File

@ -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;
};
}