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>
This commit is contained in:
Tomás Cohen Arazi 2024-05-21 10:04:17 -03:00 committed by Katrin Fischer
parent 2e06546799
commit b54c854d24
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -204,6 +204,8 @@ sub process_job {
try {
$job->process($args);
} catch {
Koha::Logger->get( { interface => 'worker' } )
->warn( sprintf "Uncaught exception processing job id=%s: %s", $job->id, $_ );
$job->status('failed')->store;
};
}