RED-6805: As Operation I want to see why downloads are in an ERROR state

added errorcause to all download dlqs containing queue name
This commit is contained in:
yhampe 2024-01-18 16:20:48 +01:00
parent 45cae62b01
commit 15611d438c
3 changed files with 31 additions and 10 deletions

View File

@ -46,18 +46,27 @@ public class DownloadDLQMessageReceiver {
String errorCause = failedMessage.getMessageProperties().getHeader(X_ERROR_INFO_HEADER);
errorCause = errorCause.substring(0,MAX_ERROR_CAUSE_LENGTH-1);
if (errorCause == null) {
errorCause = "Error occured during download job!";
errorCause = "Unknown error occured in download queue!";
}
log.warn("Handling download job in DLQ userId: {} storageId: {} - setting status to error!", downloadJob.getUserId(), downloadJob.getStorageId());
log.warn("Handling download job in DLQ userId: {} storageId: {} - setting status to error! cause: {}", downloadJob.getUserId(), downloadJob.getStorageId(), errorCause);
setDownloadFailed(downloadJob.getUserId(), downloadJob.getStorageId(), errorCause);
}
@SneakyThrows
@RabbitListener(queues = MessagingConfiguration.REPORT_DLQ)
public void handleReportDlqMessage(ReportRequestMessage reportRequestMessage) {
public void handleReportDlqMessage(Message failedMessage) {
var reportRequestMessage = objectMapper.readValue(failedMessage.getBody(), ReportRequestMessage.class);
String errorCause = failedMessage.getMessageProperties().getHeader(X_ERROR_INFO_HEADER);
if (errorCause == null) {
errorCause = "Unknown error occured in report redaction queue!";
}
else if(errorCause.length() > MAX_ERROR_CAUSE_LENGTH) {
errorCause = errorCause.substring(0,MAX_ERROR_CAUSE_LENGTH-1);
}
log.warn("Handling report request in DLQ userId: {} storageId: {} - setting status to error!", reportRequestMessage.getUserId(), reportRequestMessage.getDownloadId());
setDownloadFailed(reportRequestMessage.getUserId(), reportRequestMessage.getDownloadId());
setDownloadFailed(reportRequestMessage.getUserId(), reportRequestMessage.getDownloadId(), errorCause);
}
@ -71,11 +80,9 @@ public class DownloadDLQMessageReceiver {
private void setDownloadFailed(String userId, String downloadId) {
String errorCause = "unknown error cause";
retryTemplate.execute(retryContext -> {
log.warn("Retrying {} time to set FAILED status for downloadJob userId: {} storageId: {}", retryContext.getRetryCount(), userId, downloadId);
downloadStatusPersistenceService.updateStatus(downloadId, DownloadStatusValue.FAILED, errorCause);
downloadStatusPersistenceService.updateStatus(downloadId, DownloadStatusValue.FAILED, "error occured in unknown queue");
return null;
});
}

View File

@ -1,11 +1,15 @@
package com.iqser.red.service.persistence.management.v1.processor.service.download;
import static com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration.X_ERROR_INFO_HEADER;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.pdftron.redaction.v1.api.model.RedactionMessage;
import com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DownloadStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.settings.FileManagementServiceSettings;
import com.iqser.red.service.persistence.service.v1.api.shared.model.download.DownloadStatusValue;
import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
@ -32,6 +36,7 @@ public class RedactionDlqMessageReceiver {
RetryTemplate retryTemplate;
RabbitTemplate rabbitTemplate;
private final static int MAX_ERROR_CAUSE_LENGTH = 1024;
@RabbitHandler
@RabbitListener(queues = MessagingConfiguration.PDFTRON_DLQ)
@ -40,6 +45,14 @@ public class RedactionDlqMessageReceiver {
// Download packages will always be build on the pod that runs the scheduler, as we plan to replace the entire logic by downloading directory direct from storage, we leave it like that for now.
RedactionMessage redactionMessage = objectMapper.readValue(message.getBody(), RedactionMessage.class);
String errorCause = message.getMessageProperties().getHeader(X_ERROR_INFO_HEADER);
if (errorCause == null) {
errorCause = "Unkown error occured in pdftron service!";
}
else if(errorCause.length() > MAX_ERROR_CAUSE_LENGTH) {
errorCause = errorCause.substring(0,MAX_ERROR_CAUSE_LENGTH-1);
}
var fileEntryOptional = downloadPreparationService.getRedactionFileStatusEntry(redactionMessage.getDownloadId(), redactionMessage.getFileId());
@ -47,7 +60,7 @@ public class RedactionDlqMessageReceiver {
var entry = fileEntryOptional.get();
int numErrors = entry.getProcessingErrorCounter() + 1;
if (numErrors >= settings.getMaxRedactionFileErrorRetries()) {
setDownloadFailed(redactionMessage.getDownloadId());
setDownloadFailed(redactionMessage.getDownloadId(), errorCause);
downloadPreparationService.clearRedactionStatusEntries(redactionMessage.getDownloadId());
} else {
downloadPreparationService.increaseProcessingErrorCounter(redactionMessage, numErrors);
@ -60,11 +73,11 @@ public class RedactionDlqMessageReceiver {
}
public void setDownloadFailed(String downloadId) {
public void setDownloadFailed(String downloadId,String errorCause) {
retryTemplate.execute(retryContext -> {
log.warn("Retrying {} time to set FAILED status for downloadJob with storageId: {}", retryContext.getRetryCount(), downloadId);
downloadStatusPersistenceService.updateStatus(downloadId, DownloadStatusValue.FAILED);
downloadStatusPersistenceService.updateStatus(downloadId, DownloadStatusValue.FAILED, errorCause);
return null;
});
}

View File

@ -22,6 +22,7 @@ public interface DownloadStatusRepository extends JpaRepository<DownloadStatusEn
int updateStatus(@Param("storageId") String storageId, @Param("status") DownloadStatusValue status);
@Modifying
@Query("update DownloadStatusEntity ds set ds.status = :status, ds.errorCause = :errorCause where ds.storageId = :storageId")
int updateStatusAndErrorCause(@Param("storageId") String storageId, @Param("status") DownloadStatusValue status, @Param("errorCause") String errorCause);