-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/ai/dragon/service/IngestorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |