Skip to content

Commit

Permalink
🚧 JobScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
isontheline committed May 30, 2024
1 parent 01c74ed commit fc19450
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/main/java/ai/dragon/config/JobRunrConfig.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
7 changes: 7 additions & 0 deletions backend/src/main/java/ai/dragon/service/SiloJobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,9 @@ public class SiloJobService {
@Autowired
private SiloRepository siloRepository;

@Autowired
private JobScheduler jobScheduler;

private EntityChangeListener<SiloEntity> entityChangeListener;

@PostConstruct
Expand All @@ -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")
Expand All @@ -55,5 +60,7 @@ public void onChangeEvent(CollectionEventInfo<?> collectionEventInfo, UUID uuid)
@PreDestroy
private void destroy() {
siloRepository.unsubscribe(entityChangeListener);

// TODO Stop all Recurrent Jobs
}
}

0 comments on commit fc19450

Please sign in to comment.