47 lines
1.8 KiB
Java
47 lines
1.8 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.shouldNotRequestMore ) {
|
|
// Here we will be right after the Worker has posted its last report. It is guaranteed that the Controller will not have processed it and have not requested the full-text files.
|
|
// We do not want to shut down the controller.
|
|
return;
|
|
}
|
|
|
|
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.
|
|
AssignmentsHandler.shouldNotRequestMore = true;
|
|
return;
|
|
}
|
|
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();
|
|
}
|
|
|
|
}
|