41 lines
1.7 KiB
Java
41 lines
1.7 KiB
Java
package eu.openaire.urls_worker.components;
|
|
|
|
import eu.openaire.urls_worker.UrlsWorkerApplication;
|
|
import eu.openaire.urls_worker.controllers.GeneralController;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@Component
|
|
public class ScheduledTasks {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
|
|
|
|
|
|
@Autowired
|
|
AssignmentsHandler assignmentsHandler;
|
|
|
|
@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?
|
|
// TODO - Yes, apart from this knowledge, it may be the case that we make the Controller to request the Workers to 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();
|
|
}
|
|
|
|
}
|