2021-03-16 17:38:53 +01:00
package eu.openaire.urls_worker.components ;
2022-09-12 15:48:44 +02:00
import eu.openaire.urls_worker.UrlsWorkerApplication ;
import eu.openaire.urls_worker.controllers.GeneralController ;
2021-03-16 17:38:53 +01:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2023-01-25 17:33:49 +01:00
import org.springframework.beans.factory.annotation.Autowired ;
2021-03-16 17:38:53 +01:00
import org.springframework.scheduling.annotation.Scheduled ;
import org.springframework.stereotype.Component ;
@Component
public class ScheduledTasks {
private static final Logger logger = LoggerFactory . getLogger ( ScheduledTasks . class ) ;
2021-05-20 02:28:48 +02:00
2023-01-25 17:33:49 +01:00
@Autowired
AssignmentsHandler assignmentsHandler ;
2022-02-21 11:48:21 +01:00
@Scheduled ( fixedDelay = 1 ) // Request the next batch immediately after the last one finishes.
2021-10-14 02:03:47 +02:00
public void handleNewAssignments ( ) {
2023-05-23 21:19:41 +02:00
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 ;
}
2022-02-21 11:48:21 +01:00
if ( AssignmentsHandler . hadConnectionErrorOnRequest ) {
2023-05-23 21:19:41 +02:00
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 ;
}
2022-02-21 11:48:21 +01:00
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 ;
}
2021-11-26 16:04:31 +01:00
}
2022-02-21 11:48:21 +01:00
2023-01-25 17:33:49 +01:00
assignmentsHandler . handleAssignments ( ) ;
2021-05-20 02:28:48 +02:00
}
2021-06-22 04:58:07 +02:00
}