Skip to content

Commit

Permalink
Bug 36901: Add logging for uncaught exceptions in background job classes
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Martin Renvoize <[email protected]>
Signed-off-by: Katrin Fischer <[email protected]>
  • Loading branch information
tomascohen authored and kfischer committed Jul 1, 2024
1 parent 2e06546 commit b54c854
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion misc/workers/background_jobs_worker.pl
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ =head1 OPTIONS
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;
};
}

0 comments on commit b54c854

Please sign in to comment.