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");
}
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");
}
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);
}
}
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;
}
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");
}
Aggregations