Bug 42669: Use exception type check for NoNodes and don't mask real failures

Two follow-up fixes from QA review of the previous commit:

- Detect Search::Elasticsearch::Error::NoNodes via ref($_) rather than
  regex-matching the stringified exception, matching the existing
  pattern already used in about.pl.
- Only reset jobs to 'new' for retry when NoNodes is the sole problem.
  If a genuine indexing error also occurred in the same batch, record
  the batch as 'failed' instead of silently discarding that error via
  the NoNodes retry path.

Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-07-10 17:07:18 +01:00 committed by Lucas Gass
parent 3183061da9
commit 246d62da90
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 6 additions and 4 deletions

View File

@ -253,7 +253,7 @@ sub commit {
$auth_indexer->update_index( \@auth_chunk );
} catch {
$logger->warn( sprintf "Update of elastic index failed with: %s", $_ );
if ( "$_" =~ /NoNodes/ ) {
if ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
$no_nodes = 1;
$auth_indexer =
Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
@ -270,7 +270,7 @@ sub commit {
$biblio_indexer->update_index( \@bib_chunk );
} catch {
$logger->warn( sprintf "Update of elastic index failed with: %s", $_ );
if ( "$_" =~ /NoNodes/ ) {
if ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
$no_nodes = 1;
$biblio_indexer =
Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
@ -281,9 +281,11 @@ sub commit {
}
}
if ($no_nodes) {
if ( $no_nodes && $index_ok ) {
# ES is unreachable — reset jobs to 'new' so they are retried after reconnection
# ES is unreachable, and no other error occurred — reset jobs to 'new' so they are retried
# after reconnection. If a genuine indexing error also occurred, fall through to record
# the batch as 'failed' instead, so that error isn't masked by the retry.
$logger->warn("Elasticsearch unavailable (NoNodes), resetting jobs for retry");
$jobs->update(
{