diff --git a/src/main/java/eu/openaire/urls_worker/components/AssignmentsHandler.java b/src/main/java/eu/openaire/urls_worker/components/AssignmentsHandler.java index 4601ba1..ae83e05 100644 --- a/src/main/java/eu/openaire/urls_worker/components/AssignmentsHandler.java +++ b/src/main/java/eu/openaire/urls_worker/components/AssignmentsHandler.java @@ -108,11 +108,21 @@ public class AssignmentsHandler { try { // Here, the HTTP-request is executed. assignmentRequest = restTemplate.getForObject(requestUrl, AssignmentsRequest.class); } catch (RestClientException rce) { - logger.error("Could not retrieve the assignments!\n" + rce.getMessage()); // It shows the response body (from Spring v.2.5.6 onwards). - hadConnectionErrorOnRequest = true; + final String errorMsg = "Could not retrieve the assignments! "; + String exceptionMsg = rce.getMessage(); // It also shows the response body of the response (from Spring v.2.5.6 onwards). + if ( (exceptionMsg != null) && !exceptionMsg.isEmpty() ) { + hadConnectionErrorOnRequest = true; + logger.error(errorMsg + exceptionMsg); + } + else { // Otherwise, it's an undefined error, which occurs randomly + // and does not mean that the Controller has some problem, or the Worker requested something in a wrong way, + // or that the firewall disallow the connection (in this case we get "connection refused/timed out"). + logger.error(errorMsg, rce); + // Try again immediately, do not wait 15 mins. The Controller will take some minutes to prepare the data, before it sends them anyway. + } return null; } catch (IllegalArgumentException iae) { - logger.error("Could not retrieve the assignments, as the provided Controller's url was malformed!\n" + iae.getMessage()); + logger.error("Could not retrieve the assignments, as the provided Controller's url was malformed! " + iae.getMessage()); // We do not need to send a "ShutdownReport" to the Controller, since this error will appear upon the Worker's initialization and the Controller will not have any information about this Worker's existence. UrlsWorkerApplication.gentleAppShutdown(); } diff --git a/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java b/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java index c3ac843..f413342 100644 --- a/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java +++ b/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java @@ -61,18 +61,20 @@ public class ScheduledTasks { { if ( GeneralController.shouldShutdownWorker || AssignmentsHandler.shouldNotRequestMore ) { // Here we will be right after the Worker has posted its last report. It is guaranteed that the Controller will not have processed it and have not requested the full-text files. - // We do not want to shut down the controller. + // We do not want to shut down the Worker, until all files have been transferred to the Controller, or some time has passed. return; } - if ( rootPath.getFreeSpace() <= requiredFreeSpace ) { + // The user might have just requested the Worker to shut-down. + if ( GeneralController.shouldShutdownWorker ) { // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a data-request error-loop. + AssignmentsHandler.shouldNotRequestMore = true; + return; + } + + if ( rootPath.getFreeSpace() < requiredFreeSpace ) { // It's not safe to proceed with downloading more files and risk of "noSpaceLeft" error. // Wait for the Controller to take the full-texts and any remaining files to be deleted, so that more free-space becomes available. // We need to have some buffer zone for the ".tar" files which will be created from the already downloaded full-texts, when the Controller starts requesting them. - if ( GeneralController.shouldShutdownWorker ) { // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a free-space check loop. - AssignmentsHandler.shouldNotRequestMore = true; - return; - } logger.warn("The free space is running out (less than " + (requiredFreeSpace / oneMb) + " Mb). The Worker will avoid getting new assignments for the next 15 minutes."); try { Thread.sleep(900_000); // Sleep for 15 mins to stall the scheduler from retrying right away, thus giving time to the disk-space to be freed. @@ -83,10 +85,6 @@ public class ScheduledTasks { } if ( AssignmentsHandler.hadConnectionErrorOnRequest ) { - if ( GeneralController.shouldShutdownWorker ) { // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a data-request error-loop. - AssignmentsHandler.shouldNotRequestMore = true; - return; - } try { Thread.sleep(900_000); // Sleep for 15 mins to stall the scheduler from retrying right away, thus giving time to the Controller to recover. } catch (InterruptedException ie) {