Search in sources :

Example 6 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleServiceTest method isRetryScheduleWithFailedSchedule.

@Test
public void isRetryScheduleWithFailedSchedule() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now().plusDays(1));
    assertThat(scheduleEntity.isFailed()).isTrue();
    assertThat(scheduleService.isRetrySchedule(pipelineName, processId)).isTrue();
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleServiceTest method isRetryScheduleWithDifferentProcessId.

@Test
public void isRetryScheduleWithDifferentProcessId() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String differentProcessId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now());
    assertThat(scheduleEntity.isFailed()).isTrue();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, differentProcessId));
    assertThat(ex.getMessage()).contains("a newer process execution exists for the schedule");
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleService method isRetrySchedule.

/**
 * Returns true if there is a schedule that has failed and can be retried.
 *
 * @param pipelineName the pipeline name
 * @param processId the process id
 * @return true if there is a schedule that has failed and can be retried
 * @throws PipeliteProcessRetryException if there is a schedule that can't be retried
 */
@Timed("pipelite.transactional")
public boolean isRetrySchedule(String pipelineName, String processId) {
    Optional<ScheduleEntity> scheduleEntityOpt = getSavedSchedule(pipelineName);
    if (!scheduleEntityOpt.isPresent()) {
        return false;
    }
    ScheduleEntity scheduleEntity = scheduleEntityOpt.get();
    if (!scheduleEntity.isFailed()) {
        throw new PipeliteProcessRetryException(pipelineName, processId, "the process for the schedule is not failed");
    }
    if (!processId.equals(scheduleEntity.getProcessId())) {
        throw new PipeliteProcessRetryException(pipelineName, processId, "a newer process execution exists for the schedule: " + scheduleEntity.getProcessId());
    }
    if (scheduleEntity.getNextTime() != null && Duration.between(ZonedDateTime.now(), scheduleEntity.getNextTime()).compareTo(RETRY_MARGIN) < 0) {
        throw new PipeliteProcessRetryException(pipelineName, processId, "the next process for the schedule will be executed in less than " + RETRY_MARGIN.toMinutes() + " minutes");
    }
    return true;
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ScheduleEntity(pipelite.entity.ScheduleEntity) Timed(io.micrometer.core.annotation.Timed)

Example 9 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleService method createSchedule.

@Timed("pipelite.transactional")
public ScheduleEntity createSchedule(String serviceName, String pipelineName, String cron) {
    ScheduleEntity scheduleEntity = new ScheduleEntity();
    scheduleEntity.setCron(cron);
    scheduleEntity.setDescription(CronUtils.describe(cron));
    scheduleEntity.setPipelineName(pipelineName);
    scheduleEntity.setServiceName(serviceName);
    return saveSchedule(scheduleEntity);
}
Also used : ScheduleEntity(pipelite.entity.ScheduleEntity) Timed(io.micrometer.core.annotation.Timed)

Example 10 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleRunner method resumeSchedule.

protected void resumeSchedule(ScheduleCron scheduleCron) {
    String pipelineName = scheduleCron.getPipelineName();
    ScheduleEntity scheduleEntity = scheduleService.getSavedSchedule(pipelineName).get();
    if (!scheduleEntity.isActive()) {
        return;
    }
    logContext(log.atInfo(), pipelineName).log("Resuming schedule");
    Optional<ProcessEntity> processEntity = getSavedProcess(scheduleEntity);
    if (!processEntity.isPresent()) {
        logContext(log.atSevere(), pipelineName, scheduleEntity.getProcessId()).log("Could not resume schedule because process does not exist");
    } else {
        executeSchedule(scheduleCron, processEntity.get(), ExecuteMode.RESUME);
    }
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity)

Aggregations

ScheduleEntity (pipelite.entity.ScheduleEntity)22 ProcessEntity (pipelite.entity.ProcessEntity)9 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 ZonedDateTime (java.time.ZonedDateTime)5 Timed (io.micrometer.core.annotation.Timed)4 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)4 Schedule (pipelite.Schedule)2 StageEntity (pipelite.entity.StageEntity)2 PipeliteException (pipelite.exception.PipeliteException)2 Process (pipelite.process.Process)2 Duration (java.time.Duration)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PostConstruct (javax.annotation.PostConstruct)1 Getter (lombok.Getter)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 TestConfiguration (org.springframework.boot.test.context.TestConfiguration)1