From e72a4d3d10073f6370628fb515c3d86a4528bdaa Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Fri, 8 Sep 2023 14:11:41 +0300 Subject: [PATCH] - Improve handling of already renamed workerReport-files, which relate to failed workerReports in the 1st try. - Add check for workerReport-files, which may have been deleted before their time, due to an error. --- .../urls_controller/services/UrlsServiceImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/eu/openaire/urls_controller/services/UrlsServiceImpl.java b/src/main/java/eu/openaire/urls_controller/services/UrlsServiceImpl.java index 8b1c8d0..7494cc1 100644 --- a/src/main/java/eu/openaire/urls_controller/services/UrlsServiceImpl.java +++ b/src/main/java/eu/openaire/urls_controller/services/UrlsServiceImpl.java @@ -517,6 +517,17 @@ public class UrlsServiceImpl implements UrlsService { // Rename the worker-report to indicate success or failure. String workerReportBaseName = this.workerReportsDirPath + File.separator + workerId + File.separator + workerId + "_assignments_" + assignmentRequestCounter + "_report"; File workerReport = new File(workerReportBaseName + ".json"); + + // Check if the workerReport does not exist under this name, as it may have been renamed previously to "failed" and now is the 2nd try. + if ( ! workerReport.isFile() ) { + // Then this is the 2nd try and the report has already been renamed to "failed" the 1st time. + workerReport = new File(workerReportBaseName + "_failed.json"); + if ( ! workerReport.isFile() ) { // In this case, an error exists, since this file was deleted before its time. + logger.error("The workerReport file \"" + workerReport.getAbsolutePath() + "\" does not exist!"); + // TODO - How to handle it? This report may be either successful or failed but the file was deleted. + } + } + File renamedWorkerReport = new File(workerReportBaseName + ((errorMsg == null) ? "_successful.json" : "_failed.json")); boolean wasWorkerReportRenamed = true; try {