Bug 34070: Add error handling for ERROR frames for background worker

This change adds error handling for ERROR frames to background_jobs_worker.pl.
A previous patch added it to es_indexer_daemon.pl which is a different
background jobs worker.

To test ERROR handling for background_jobs_worker.pl:
1. Change your RabbitMQ connection details in koha-conf.xml or the hard-coded ones in Koha/BackgroundJob.pm
to include an invalid password. For example, if you don't have a message_broker already defined, use the following:
<message_broker>
 <password>bad</password>
</message_broker>
2. sudo koha-worker --restart --quiet kohadev
3. View the errors in the logs:
tail -f /var/log/koha/kohadev/worker-output.log
tail -f /var/log/koha/kohadev/worker-error.log

To test MESSAGE handling for background_jobs_worker.pl:
1. Ensure RabbitMQ connection details are correct
2. Go to Batch item modification and add the following barcodes:
39999000001310
39999000004571
3. Add a z - Public Note of the following and click Save:
THEBACKGROUNDWORKERWORKED
4. Search the catalogue using THEBACKGROUNDWORKERWORKED in the top
catalogue search
5. Note that you get 2 results in your search
6. Look in the logs just to make sure there are no new messages there

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
David Cook 2025-03-07 01:43:25 +00:00 committed by Katrin Fischer
parent 2c1314ead6
commit 4dc4a232c4
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 21 additions and 2 deletions

View File

@ -124,8 +124,27 @@ while (1) {
}
my $args = try {
my $body = $frame->body;
decode_json($body); # TODO Should this be from_json? Check utf8 flag.
my $command = $frame->command;
my $body = $frame->body;
my $content_type = $frame->content_type;
if ( $command && $command eq 'MESSAGE' ) {
if ( $content_type && $content_type eq 'application/json' ) {
decode_json($body); # TODO Should this be from_json? Check utf8 flag.
} else {
#TODO: This is a fallback for older enqueued messages which are missing the content-type header
#TODO: Please replace this decode with a die in the future once content-type is well established
decode_json($body); # TODO Should this be from_json? Check utf8 flag.
}
} elsif ( $command && $command eq 'ERROR' ) {
#Known errors:
#You must log in using CONNECT first
#"NACK" must include a valid "message-id" header
Koha::Logger->get( { interface => 'worker' } )
->warn( sprintf "Shutting down after receiving ERROR frame:\n%s\n", $frame->as_string );
exit 1;
}
} catch {
Koha::Logger->get( { interface => 'worker' } )->warn( sprintf "Frame not processed - %s", $_ );
return;