Skip to content

Commit

Permalink
Begin JobRunr Ingestor Job
Browse files Browse the repository at this point in the history
  • Loading branch information
amengus87 committed May 28, 2024
1 parent 044e380 commit 8bde6e3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions backend/src/main/java/ai/dragon/service/IngestorService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ai.dragon.service;

import org.jobrunr.jobs.annotations.Job;
import org.jobrunr.jobs.annotations.Recurring;
import org.jobrunr.jobs.context.JobContext;
import org.jobrunr.jobs.context.JobRunrDashboardLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class IngestorService {
private final Logger logger = new JobRunrDashboardLogger(LoggerFactory.getLogger(this.getClass()));

public static final String INGESTOR_RECURRING_JOB_ID = "ingestor-recurring-job";

@Recurring(id = INGESTOR_RECURRING_JOB_ID, cron = "* * * * *")
@Job(name = "Ingestor Recurring Job")
public void executeSampleJob(JobContext jobContext) {
logger.info("testinfo");
jobContext.logger().info("new info");
}
}
40 changes: 40 additions & 0 deletions backend/src/main/java/ai/dragon/service/JobService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ai.dragon.service;

import org.jobrunr.jobs.Job;
import org.jobrunr.jobs.RecurringJob;
import org.jobrunr.storage.JobNotFoundException;
import org.jobrunr.storage.RecurringJobsResult;
import org.jobrunr.storage.StorageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JobService {
private RecurringJobsResult recurringJobsResult;

@Autowired
private StorageProvider storageProvider;

public void onApplicationStartup() {
this.triggerRecurringJob(IngestorService.INGESTOR_RECURRING_JOB_ID);
}

public void triggerRecurringJob(String id) {
final RecurringJob recurringJob = recurringJobResults()
.stream()
.filter(rj -> rj.getId().equals(id))
.findFirst()
.orElseThrow(() -> new JobNotFoundException(id));

final Job job = recurringJob.toEnqueuedJob();
storageProvider.save(job);
}

private RecurringJobsResult recurringJobResults() {
if (recurringJobsResult == null
|| storageProvider.recurringJobsUpdated(recurringJobsResult.getLastModifiedHash())) {
recurringJobsResult = storageProvider.getRecurringJobs();
}
return recurringJobsResult;
}
}

0 comments on commit 8bde6e3

Please sign in to comment.