- Add the "shutdownWorker"-endpoint to accept requests for shutting-down the Worker, gracefully, after it completes its current work (including sending the publications-files to the Controller). A user-defined "auth-code" is required.
@ -64,7 +64,7 @@ public class UrlsWorkerApplication {
publicstaticvoidgentleAppShutdown()
{
intexitCode=SpringApplication.exit(context,()->0);// The "PreDestroy" method will be called.
intexitCode=SpringApplication.exit(context,()->0);// The "PreDestroy" method will be called. (the "context" will be closed automatically (I checked it))
System.exit(exitCode);
}
@ -145,10 +145,10 @@ public class UrlsWorkerApplication {
logger.warn("The given \"maxAssignmentsBatchesToHandleBeforeRestart\" ("+maxAssignmentsBatchesStr+") was not a number! Will handle an infinite number of batches!");
maxAssignmentsBatchesToHandleBeforeRestart=0;
maxAssignmentsBatchesToHandleBeforeShutdown=0;
}
controllerBaseUrl=data[3].trim();
try{
@ -163,14 +163,14 @@ public class UrlsWorkerApplication {
controllerBaseUrl+="/";// Make sure the other urls will not break later.
StringerrorMsg="No \"workerId\" or/and \"maxAssignmentsLimitPerBatch\" or/and \"maxAssignmentsBatchesToHandleBeforeRestart\" or/and \"controllerBaseUrl\" could be retrieved from the file: "+inputDataFilePath;
logger.error(errorMsg);
System.err.println(errorMsg);
System.exit(63);
}
logger.info("workerId: "+workerId+", maxAssignmentsLimitPerBatch: "+maxAssignmentsLimitPerBatch+", maxAssignmentsBatchesToHandleBeforeRestart: "+maxAssignmentsBatchesToHandleBeforeRestart+", controllerBaseUrl: "+controllerBaseUrl);// It's safe and helpful to show them in the logs.
logger.info("workerId: "+workerId+", maxAssignmentsLimitPerBatch: "+maxAssignmentsLimitPerBatch+", maxAssignmentsBatchesToHandleBeforeRestart: "+maxAssignmentsBatchesToHandleBeforeShutdown+", controllerBaseUrl: "+controllerBaseUrl);// It's safe and helpful to show them in the logs.
}catch(Exceptione){
StringerrorMsg="An error prevented the retrieval of the workerId and the controllerBaseUrl from the file: "+inputDataFilePath+"\n"+e.getMessage();
StringinitMsg="Received a \"cancelShutdownWorker\" request.";
if(cancelCode.equals(shutdownOrCancelCode)){
shouldShutdownWorker=false;
logger.info(initMsg+" Any previous \"shutdownWorker\"-request is canceled. The \"maxAssignmentsBatchesToHandleBeforeShutdown\" will still be honored (if it's set).");
returnResponseEntity.ok().build();
}else{
StringerrorMsg=initMsg+" But, it has an invalid \"cancelCode\": "+cancelCode;
@ -129,7 +130,7 @@ public class AssignmentsHandler {
else
postWorkerReport(assignmentRequestCounter);
numHandledAssignmentsBatches++;// This is used later to stop this app, when a user-defined upper limit is reached.
numHandledAssignmentsBatches++;// This is used later to stop this app, if a user-defined upper limit is set and reached.
// Every time we reach a "limit" of handled id-url clear some data-structures of the underlying "PublicationsRetriever" program.
// This helps with reducing the memory consumption over the period of weeks or months, and also give a 2nd chance to some domains which may be blocked due to a connectivity issues, but after a month they may be fine.
@ -140,9 +141,12 @@ public class AssignmentsHandler {
logger.info("The maximum assignments-batches ("+UrlsWorkerApplication.maxAssignmentsBatchesToHandleBeforeRestart+") to be handled was reached! Shut down, in order for the external Linux-service to restart on its own..");
logger.info("The worker will now shutdown, as "+(GeneralController.shouldShutdownWorker
?"it received a \"shutdownWorker\" request!"
:"the maximum assignments-batches ("+UrlsWorkerApplication.maxAssignmentsBatchesToHandleBeforeShutdown+") to be handled was reached!"));
UrlsWorkerApplication.gentleAppShutdown();
// The "gentleAppShutdown()" will exit the app, so the "isAvailableForWork" will not be set below.
}
@ -152,6 +156,10 @@ public class AssignmentsHandler {