When at least one worker is still active and have to wait for service-shutdown, show a log-message to inform the user, including that worker's IP.

This commit is contained in:
Lampros Smyrnaios 2024-01-15 13:35:22 +02:00
parent 3a70b57146
commit bdc61c2cda
1 changed files with 10 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import eu.openaire.urls_controller.controllers.BulkImportController;
import eu.openaire.urls_controller.controllers.ShutdownController;
import eu.openaire.urls_controller.controllers.StatsController;
import eu.openaire.urls_controller.controllers.UrlsController;
import eu.openaire.urls_controller.models.WorkerInfo;
import eu.openaire.urls_controller.payloads.requests.WorkerReport;
import eu.openaire.urls_controller.services.UrlsServiceImpl;
import eu.openaire.urls_controller.util.FileUtils;
@ -173,14 +174,19 @@ public class ScheduledTasks {
// Check whether the workers have not shutdown yet, which means that they either crawl assignments or/and they are waiting for the Controller to process the WorkerReport and then shutdown.
Set<String> workerIds = UrlsController.workersInfoMap.keySet();
if ( workerIds.size() > 0 ) {
for ( String workerId : workerIds )
if ( ! UrlsController.workersInfoMap.get(workerId).getHasShutdown() ) // The workerId is certainly inside the map and has a workerInfo value.
for ( String workerId : workerIds ) {
WorkerInfo workerInfo = UrlsController.workersInfoMap.get(workerId); // The workerId is certainly inside the map and has a workerInfo value.
if ( ! workerInfo.getHasShutdown() ) {
logger.debug("At least one worker (with IP: " + workerInfo.getWorkerIP() + ") is still active. Waiting for all workers to shutdown, before shutting down the service.");
return; // If at least 1 worker is still active, then do not shut down the Controller.
}
}
logger.info("All workers have already shutdown. Shutting down the Controller..");
} else
logger.info("No workers have participated in the service yet, so the Controller will shut-down immediately.");
logger.info("No workers have participated in the service yet. The Controller will shut-down now.");
// If one worker has crashed, then it will have not informed the Controller. So the controller will think that it is still running and will not shut down.
// IMPORTANT: If one worker has crashed, then it will have not informed the Controller. So the controller will think that it is still running and will not shut down..!
// In this case, we have to manually shut-down the service, from Docker cli.
// Any left-over worker-reports are kept to be retried next time the Controller starts.