use of pipelite.process.Process in project pipelite by enasequence.
the class RetryServiceTest method retryFailedProcess.
@Test
public void retryFailedProcess() {
String processId = PipeliteIdCreator.processId();
RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
Process process = ProcessFactory.create(processId, registeredPipeline);
// Failed process
process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
processService.startExecution(process.getProcessEntity());
ProcessEntity processEntity = processService.endExecution(process, ProcessState.FAILED);
// Failed stage
Stage stage = process.getStage(STAGE_NAME).get();
stageService.createExecution(PIPELINE_NAME, processId, stage);
stageService.startExecution(stage);
stageService.endExecution(stage, StageExecutorResult.error());
StageEntity stageEntity = stage.getStageEntity();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
// Retry
retryService.retry(PIPELINE_NAME, processId);
// Check process state
processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
assertThat(processEntity.getPipelineName()).isEqualTo(PIPELINE_NAME);
assertThat(processEntity.getProcessId()).isEqualTo(processId);
assertThat(processEntity.getStartTime()).isNotNull();
assertThat(processEntity.getEndTime()).isNull();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.ACTIVE);
// Check stage state
stageEntity = stageService.getSavedStage(PIPELINE_NAME, processId, STAGE_NAME).get();
assertThat(stageEntity.getPipelineName()).isEqualTo(PIPELINE_NAME);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(STAGE_NAME);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
assertThat(stageEntity.getStartTime()).isNull();
assertThat(stageEntity.getEndTime()).isNull();
}
use of pipelite.process.Process in project pipelite by enasequence.
the class MailService method getStagesLogText.
String getStagesLogText(Process process) {
if (!process.getStages().stream().anyMatch(s -> s.isError())) {
return "";
}
String text = "\nError logs:\n---------------\n";
for (Stage stage : process.getStages()) {
if (stage.isError()) {
Optional<StageLogEntity> stageLogEntity = stageService.getSavedStageLog(process.getProcessEntity().getPipelineName(), process.getProcessId(), stage.getStageName());
if (stageLogEntity.isPresent()) {
String log = stageLogEntity.get().getStageLog();
if (log != null && !log.isEmpty()) {
text += "\nStage: " + stage.getStageName() + "\n===============\n";
text += log.substring(Math.max(0, log.length() - advancedConfiguration.getMailLogBytes())) + "\n";
}
}
}
}
return text;
}
use of pipelite.process.Process 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.process.Process in project pipelite by enasequence.
the class PipelineRunner method runProcess.
protected void runProcess(ProcessEntity processEntity) {
internalErrorHandler.execute(() -> {
Process process = ProcessFactory.create(processEntity, pipeline);
runProcess(pipelineName, process, (p) -> {
});
});
}
use of pipelite.process.Process in project pipelite by enasequence.
the class ScheduleRunner method executeSchedule.
protected void executeSchedule(ScheduleCron scheduleCron, ProcessEntity processEntity, ExecuteMode executeMode) {
internalErrorHandler.execute(() -> {
String pipelineName = processEntity.getPipelineName();
String processId = processEntity.getProcessId();
logContext(log.atInfo(), pipelineName, processId).log("Executing scheduled process");
Schedule schedule = getSchedule(pipelineName);
if (schedule == null) {
return;
}
Process process = getProcess(processEntity, schedule);
if (process == null) {
return;
}
setMaximumRetries(process);
if (executeMode != ExecuteMode.RESUME) {
scheduleService.startExecution(pipelineName, processId);
}
scheduleCron.setLaunchTime(null);
runProcess(pipelineName, process, (p) -> {
ScheduleEntity scheduleEntity = scheduleService.getSavedSchedule(pipelineName).get();
ZonedDateTime nextLaunchTime = CronUtils.launchTime(scheduleCron.getCron(), scheduleEntity.getStartTime());
internalErrorHandler.execute(() -> scheduleService.endExecution(processEntity, nextLaunchTime));
scheduleCron.setLaunchTime(nextLaunchTime);
decreaseMaximumExecutions(pipelineName);
});
});
}
Aggregations