Search in sources :

Example 1 with PipeliteProcessRetryException

use of pipelite.exception.PipeliteProcessRetryException in project pipelite by enasequence.

the class ScheduleServiceTest method isRetryScheduleWithNewExecutionWithinRetryMargin.

@Test
public void isRetryScheduleWithNewExecutionWithinRetryMargin() {
    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());
    assertThat(scheduleEntity.isFailed()).isTrue();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, processId));
    assertThat(ex.getMessage()).contains("the next process for the schedule will be executed in less than");
}
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 2 with PipeliteProcessRetryException

use of pipelite.exception.PipeliteProcessRetryException 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 3 with PipeliteProcessRetryException

use of pipelite.exception.PipeliteProcessRetryException in project pipelite by enasequence.

the class RetryService method retry.

/**
 * Retries a failed process.
 *
 * @param pipelineName the pipeline name
 * @param processId the processId
 * @throws PipeliteProcessRetryException if the process can't be retried
 */
public void retry(String pipelineName, String processId) {
    processService.isRetryProcess(pipelineName, processId);
    boolean isRetrySchedule = scheduleService.isRetrySchedule(pipelineName, processId);
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(pipelineName);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Retry stages
    for (Stage stage : process.getStages()) {
        stage.setStageEntity(getSavedStage(pipelineName, processId, stage.getStageName()));
        if (DependencyResolver.isPermanentlyFailedStage(stage)) {
            stage.getStageEntity().resetExecution();
            stageService.saveStage(stage);
        }
    }
    // Retry process
    process.setProcessEntity(getSavedProcess(pipelineName, processId));
    processService.startExecution(process.getProcessEntity());
    // Retry schedule
    if (isRetrySchedule) {
        ScheduleRunner scheduler = runnerService.getScheduleRunner();
        if (scheduler == null) {
            throw new PipeliteProcessRetryException(pipelineName, processId, "missing scheduler");
        }
        scheduler.retrySchedule(pipelineName, processId);
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Stage(pipelite.stage.Stage) RegisteredPipeline(pipelite.RegisteredPipeline) Process(pipelite.process.Process)

Example 4 with PipeliteProcessRetryException

use of pipelite.exception.PipeliteProcessRetryException 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 5 with PipeliteProcessRetryException

use of pipelite.exception.PipeliteProcessRetryException in project pipelite by enasequence.

the class ScheduleServiceTest method isRetryScheduleWithNotFailedSchedule.

@Test
public void isRetryScheduleWithNotFailedSchedule() {
    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();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, processId));
    assertThat(ex.getMessage()).contains("the process for the schedule is not failed");
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)5 ScheduleEntity (pipelite.entity.ScheduleEntity)4 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ProcessEntity (pipelite.entity.ProcessEntity)2 Timed (io.micrometer.core.annotation.Timed)1 RegisteredPipeline (pipelite.RegisteredPipeline)1 Process (pipelite.process.Process)1 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)1 Stage (pipelite.stage.Stage)1