- Show the full stacktrace in the weird case of a "RestClientException" without an exception-message. Also, in this case, retry immediately, as there is no long-lasting network problem that requires some time between requests, but most probably a random interruption.

- Code polishing.
This commit is contained in:
Lampros Smyrnaios 2023-10-27 17:36:54 +03:00
parent 10e39d79a4
commit bfa76e9484
2 changed files with 21 additions and 13 deletions

View File

@ -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();
}

View File

@ -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) {