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