use of org.springframework.retry.RetryCallback in project ArachneCentralAPI by OHDSI.
the class AntivirusServiceImpl method processRequest.
@EventListener
@Async(value = "antivirusScanExecutor")
public void processRequest(AntivirusJobEvent event) {
final AntivirusJob antivirusJob = event.getAntivirusJob();
final AntivirusJobFileType fileType = antivirusJob.getAntivirusJobFileType();
final Long fileId = antivirusJob.getFileId();
logger.debug(PROCESSING_SCAN_REQUEST, fileId, fileType);
String description = null;
AntivirusStatus status;
try {
final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
return scan(antivirusJob.getContent());
});
if (scan instanceof ScanResult.OK) {
status = AntivirusStatus.OK;
} else {
status = AntivirusStatus.INFECTED;
description = scan.toString();
}
} catch (Exception e) {
logger.error("Error scanning file: {}", e.getMessage());
if (e instanceof ClamavException) {
final Throwable cause = e.getCause();
description = cause.getMessage();
} else {
description = e.getMessage();
}
status = AntivirusStatus.NOT_SCANNED;
}
logger.debug(PROCESSING_SCAN_RESULT, fileId, fileType, status);
publishResponse(fileType, fileId, status, description);
}
Aggregations