TSK-1555: Initialize due of Cleanup Job based on firstRun (#1488)
* TSK-1555: Initialize due of Cleanup Job based on firstRun * TSK-1555: Improvements after review
This commit is contained in:
parent
d57aeb3219
commit
ec822c1168
|
@ -15,6 +15,7 @@ import pro.taskana.common.internal.transaction.TaskanaTransactionProvider;
|
|||
/** Abstract base for all background jobs of TASKANA. */
|
||||
public abstract class AbstractTaskanaJob implements TaskanaJob {
|
||||
|
||||
protected final Instant firstRun;
|
||||
protected final Duration runEvery;
|
||||
protected TaskanaEngineImpl taskanaEngineImpl;
|
||||
protected TaskanaTransactionProvider<Object> txProvider;
|
||||
|
@ -27,6 +28,7 @@ public abstract class AbstractTaskanaJob implements TaskanaJob {
|
|||
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
this.txProvider = txProvider;
|
||||
this.scheduledJob = job;
|
||||
firstRun = taskanaEngine.getConfiguration().getCleanupJobFirstRun();
|
||||
this.runEvery = taskanaEngineImpl.getConfiguration().getCleanupJobRunEvery();
|
||||
}
|
||||
|
||||
|
@ -60,7 +62,7 @@ public abstract class AbstractTaskanaJob implements TaskanaJob {
|
|||
}
|
||||
|
||||
protected Instant getNextDueForCleanupJob() {
|
||||
Instant nextRun = Instant.now();
|
||||
Instant nextRun = firstRun;
|
||||
if (scheduledJob != null && scheduledJob.getDue() != null) {
|
||||
nextRun = scheduledJob.getDue();
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ public interface TaskService {
|
|||
Task getTask(String taskId) throws TaskNotFoundException, NotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the
|
||||
* Transfer a Task to another work basket. The transfer sets the transferred flag and resets the
|
||||
* read flag.
|
||||
*
|
||||
* @param taskId The id of the {@link Task} to be transferred
|
||||
|
|
|
@ -179,18 +179,43 @@ class TaskCleanupJobAccTest extends AbstractAccTest {
|
|||
jobService.createJob(scheduledJob);
|
||||
jobsToRun = jobMapper.findJobsToRun(Instant.now());
|
||||
|
||||
assertThat(jobsToRun).hasSize(1);
|
||||
assertThat(jobsToRun.get(0).getDue()).isEqualTo(firstDue);
|
||||
assertThat(jobsToRun).extracting(ScheduledJob::getDue).containsExactly(firstDue);
|
||||
|
||||
JobRunner runner = new JobRunner(taskanaEngine);
|
||||
runner.runJobs();
|
||||
Duration runEvery = taskanaEngineConfiguration.getCleanupJobRunEvery();
|
||||
jobsToRun = jobMapper.findJobsToRun(Instant.now().plus(runEvery));
|
||||
|
||||
assertThat(jobsToRun).hasSize(1);
|
||||
assertThat(jobsToRun).extracting(ScheduledJob::getDue).containsExactly(firstDue.plus(runEvery));
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ScheduleNextJobAccordingToFirstRun_When_PreviousJobNotExisting() throws Exception {
|
||||
Instant firstRun = Instant.now().minus(2, ChronoUnit.MINUTES).truncatedTo(ChronoUnit.MILLIS);
|
||||
Duration runEvery = Duration.ofMinutes(5);
|
||||
taskanaEngineConfiguration.setCleanupJobRunEvery(runEvery);
|
||||
taskanaEngineConfiguration.setCleanupJobFirstRun(firstRun);
|
||||
|
||||
TaskCleanupJob.initializeSchedule(taskanaEngine);
|
||||
|
||||
List<ScheduledJob> nextJobs = getJobMapper().findJobsToRun(Instant.now().plus(runEvery));
|
||||
assertThat(nextJobs).extracting(ScheduledJob::getDue).containsExactly(firstRun.plus(runEvery));
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FindNoJobsToRunUntilFirstRunIsReached_When_CleanupScheduleIsInitialized()
|
||||
throws Exception {
|
||||
taskanaEngineConfiguration.setCleanupJobRunEvery(Duration.ZERO);
|
||||
taskanaEngineConfiguration.setCleanupJobFirstRun(Instant.now().plus(5, ChronoUnit.MINUTES));
|
||||
|
||||
TaskCleanupJob.initializeSchedule(taskanaEngine);
|
||||
|
||||
List<ScheduledJob> nextJobs = getJobMapper().findJobsToRun(Instant.now());
|
||||
assertThat(nextJobs).isEmpty();
|
||||
}
|
||||
|
||||
private String createAndInsertTask(String parentBusinessProcessId) throws Exception {
|
||||
Task newTask = taskService.newTask("user-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
|
|
Loading…
Reference in New Issue