diff --git a/backend/src/main/java/ai/dragon/config/JobRunrConfig.java b/backend/src/main/java/ai/dragon/config/JobRunrConfig.java index 61730b78..9c7f8421 100644 --- a/backend/src/main/java/ai/dragon/config/JobRunrConfig.java +++ b/backend/src/main/java/ai/dragon/config/JobRunrConfig.java @@ -1,6 +1,8 @@ package ai.dragon.config; +import org.jobrunr.configuration.JobRunr; import org.jobrunr.jobs.mappers.JobMapper; +import org.jobrunr.scheduling.JobScheduler; import org.jobrunr.storage.InMemoryStorageProvider; import org.jobrunr.storage.StorageProvider; import org.springframework.context.annotation.Bean; @@ -14,4 +16,14 @@ public StorageProvider storageProvider(JobMapper jobMapper) { storageProvider.setJobMapper(jobMapper); return storageProvider; } + + @Bean + public JobScheduler jobScheduler(StorageProvider storageProvider) { + return JobRunr.configure() + .useStorageProvider(storageProvider) + .useBackgroundJobServer() + .useDashboard() + .initialize() + .getJobScheduler(); + } } diff --git a/backend/src/main/java/ai/dragon/service/SiloJobService.java b/backend/src/main/java/ai/dragon/service/SiloJobService.java index 940a7961..bbf79dbe 100644 --- a/backend/src/main/java/ai/dragon/service/SiloJobService.java +++ b/backend/src/main/java/ai/dragon/service/SiloJobService.java @@ -6,6 +6,7 @@ import org.dizitart.no2.collection.events.EventType; import org.jobrunr.jobs.context.JobRunrDashboardLogger; import org.jobrunr.scheduling.BackgroundJob; +import org.jobrunr.scheduling.JobScheduler; import org.jobrunr.scheduling.RecurringJobBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,6 +27,9 @@ public class SiloJobService { @Autowired private SiloRepository siloRepository; + @Autowired + private JobScheduler jobScheduler; + private EntityChangeListener entityChangeListener; @PostConstruct @@ -43,6 +47,7 @@ public void onChangeEvent(CollectionEventInfo collectionEventInfo, UUID uuid) // Create Recurrent Job for each Silo siloRepository.find().forEach(siloEntity -> { logger.info(String.format("Creating Silo Ingestor Job : %s", siloEntity.getUuid().toString())); + BackgroundJob.setJobScheduler(jobScheduler); RecurringJobBuilder jobBuilder = RecurringJobBuilder.aRecurringJob() .withId(siloEntity.getUuid().toString()) .withName("Silo Ingestor Job") @@ -55,5 +60,7 @@ public void onChangeEvent(CollectionEventInfo collectionEventInfo, UUID uuid) @PreDestroy private void destroy() { siloRepository.unsubscribe(entityChangeListener); + + // TODO Stop all Recurrent Jobs } }