UrlsWorker/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java

37 lines
1.5 KiB
Java

package eu.openaire.urls_worker.components;
import eu.openaire.urls_worker.UrlsWorkerApplication;
import eu.openaire.urls_worker.controllers.GeneralController;
import eu.openaire.urls_worker.util.AssignmentsHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduledTasks {
private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
@Scheduled(fixedDelay = 1) // Request the next batch immediately after the last one finishes.
public void handleNewAssignments() {
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.
// TODO - Should this worker inform the Controller that will shutdown?
UrlsWorkerApplication.gentleAppShutdown();
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) {
logger.warn("Sleeping was interrupted!");
} finally {
AssignmentsHandler.hadConnectionErrorOnRequest = false;
}
}
AssignmentsHandler.handleAssignments();
}
}