Skip to content

Commit

Permalink
MAINT-2550 Avoid excessive logging when classification job failed due…
Browse files Browse the repository at this point in the history
… to timeout
  • Loading branch information
CoderMChu committed May 8, 2024
1 parent 4fb9856 commit bff2011
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public class ClassificationService {
private final List<Classification> classificationsInProgress;
private final Map<String, SecurityContext> 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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:{}",
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit bff2011

@pgwilliams
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely!

Please sign in to comment.