From bff2011cbce3ecb5540d38f07c8b33d494d1c836 Mon Sep 17 00:00:00 2001 From: CoderMChu Date: Wed, 8 May 2024 14:54:17 +0100 Subject: [PATCH] MAINT-2550 Avoid excessive logging when classification job failed due to timeout --- .../classification/ClassificationService.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/snomed/snowstorm/core/data/services/classification/ClassificationService.java b/src/main/java/org/snomed/snowstorm/core/data/services/classification/ClassificationService.java index 43ab507d4..88cb8a30c 100644 --- a/src/main/java/org/snomed/snowstorm/core/data/services/classification/ClassificationService.java +++ b/src/main/java/org/snomed/snowstorm/core/data/services/classification/ClassificationService.java @@ -125,7 +125,6 @@ public class ClassificationService { private final List classificationsInProgress; private final Map classificationUserIdToUserContextMap; - private Thread classificationStatusPollingThread; private boolean shutdownRequested; public static final int RESULT_PROCESSING_THREADS = 2;// Two threads is a good limit here. The processing is very Elasticsearch heavy while looking up inferred-not-stated values. @@ -177,7 +176,7 @@ private void init() throws ServiceException { } // Start thread to continuously fetch the status of remote classifications - classificationStatusPollingThread = new Thread(() -> { + Thread classificationStatusPollingThread = new Thread(() -> { try { while (!shutdownRequested) { try { @@ -205,14 +204,6 @@ private void init() throws ServiceException { if (timeout || classification.getStatus() != newStatus) { // Status change to process - - // Stop polling if no longer needed - if (newStatus != ClassificationStatus.SCHEDULED && newStatus != ClassificationStatus.RUNNING) { - synchronized (classificationsInProgress) { - classificationsInProgress.remove(classification); - } - } - if (newStatus == ClassificationStatus.FAILED) { classification.setErrorMessage(statusResponse.getErrorMessage()); logger.warn("Remote classification failed with message:{}, developerMessage:{}", @@ -222,6 +213,13 @@ private void init() throws ServiceException { classification.setErrorMessage("Remote service taking too long."); } + // Stop polling if no longer needed after timeout or processed + if (newStatus != ClassificationStatus.SCHEDULED && newStatus != ClassificationStatus.RUNNING) { + synchronized (classificationsInProgress) { + classificationsInProgress.remove(classification); + } + } + final ClassificationStatus newStatusFinal = newStatus; classificationProcessingExecutor.submit(() -> { classification.setStatus(newStatusFinal); @@ -264,7 +262,11 @@ private void init() throws ServiceException { classificationRepository.save(classification); jmsTemplate.convertAndSend(jmsQueuePrefix + ".authoring.classification.status", statusResponse); - logger.info("Classification {} {} after {} seconds.", classification.getId(), classification.getStatus(), getSecondsSince(classification.getCreationDate())); + if (timeout) { + logger.warn("Classification {} aborted after {} minutes.", classification.getId(), abortRemoteClassificationAfterMinutes); + } else { + logger.info("Classification {} {} after {} seconds.", classification.getId(), classification.getStatus(), getSecondsSince(classification.getCreationDate())); + } }); } if (shutdownRequested) {