- Add check for "shouldShutdownService" before allowing to continue with a bulk-import request.

- Add check for remaining background tasks (including bulkImports), before checking if the workers have shut down and then shut down the Service.
This commit is contained in:
Lampros Smyrnaios 2023-07-21 16:19:00 +03:00
parent cec2531737
commit 9cbac77c2a
3 changed files with 14 additions and 3 deletions

View File

@ -111,7 +111,9 @@ public class ScheduledTasks {
if ( ! ShutdownController.shouldShutdownService ) if ( ! ShutdownController.shouldShutdownService )
return; // Either the service was never instructed to shut down, or the user canceled the request. return; // Either the service was never instructed to shut down, or the user canceled the request.
// If the workers have shutdown on their own, without been instructed to by the Controller, then the Controller will keep running. // Check whether there are still background tasks to be processed. Either workerReport or Bulk-import requests.
if ( UrlsController.backgroundCallableTasks.size() > 0 )
return;
Set<String> workerIds = UrlsController.workersInfoMap.keySet(); Set<String> workerIds = UrlsController.workersInfoMap.keySet();
if ( workerIds.size() > 0 ) { if ( workerIds.size() > 0 ) {
@ -122,6 +124,8 @@ public class ScheduledTasks {
} else } 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, so the Controller will shut-down immediately.");
// 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.
Application.gentleAppShutdown(); Application.gentleAppShutdown();
} }

View File

@ -143,6 +143,13 @@ public class BulkImportController {
return ResponseEntity.internalServerError().body(errorMsg); return ResponseEntity.internalServerError().body(errorMsg);
} }
// After applying all the logic-checks and informing the user of any mistake, then we check and inform if the Service is about to shut down.
if ( ShutdownController.shouldShutdownService ) {
String warnMsg = "The Service is about to shutdown, after all under-processing assignments and/or bulkImport requests are handled. No new requests are accepted!";
logger.warn(warnMsg);
return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg);
}
// Detect if the same directory is scheduled for being processed. In that case, return a 429. // Detect if the same directory is scheduled for being processed. In that case, return a 429.
if ( ! bulkImportDirs.add(bulkImportDir) ) { if ( ! bulkImportDirs.add(bulkImportDir) ) {
// We allow multiple jobs for the same provenance, running at the same time, but not multiple jobs for the same bulkImportDirectory. // We allow multiple jobs for the same provenance, running at the same time, but not multiple jobs for the same bulkImportDirectory.

View File

@ -95,9 +95,9 @@ public class UrlsController {
// There might be the case that the Controller has not sent shutDown requests to the Workers yet, or it has, BUT: // There might be the case that the Controller has not sent shutDown requests to the Workers yet, or it has, BUT:
// 1) A worker requests for new assignments before the shutDown request in handled by its side. // 1) A worker requests for new assignments before the shutDown request in handled by its side.
// 2) A new Worker joins the Service (unexpected, but anyway). // 2) A new Worker joins the Service (unexpected, but anyway).
String warnMsg = "The Service is about to shutdown, after all under-processing assignments are handled. No new requests are accepted!"; String warnMsg = "The Service is about to shutdown, after all under-processing assignments and/or bulkImport requests are handled. No new requests are accepted!";
logger.warn(warnMsg); // It's likely not an actual error, but still it's not accepted. logger.warn(warnMsg); // It's likely not an actual error, but still it's not accepted.
return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg); // The worker will wait 15 mins and upon going to retry it will notice that it should not do a new request or it may have shutdown in the meantime. return ResponseEntity.status(HttpStatus.CONFLICT).body(warnMsg); // The worker will wait 15 mins and upon going to retry it will notice that it should not do a new request then or it may have already shutdown in the meantime.
} }
if ( request == null ) { if ( request == null ) {