Search in sources :

Example 16 with Process

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();
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with Process

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;
}
Also used : StageState(pipelite.stage.StageState) InternalErrorHandler(pipelite.error.InternalErrorHandler) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) RetryTask(pipelite.executor.task.RetryTask) AdvancedConfiguration(pipelite.configuration.AdvancedConfiguration) ProcessState(pipelite.process.ProcessState) Stage(pipelite.stage.Stage) Flogger(lombok.extern.flogger.Flogger) Component(org.springframework.stereotype.Component) MailConfiguration(pipelite.configuration.MailConfiguration) Optional(java.util.Optional) ServiceConfiguration(pipelite.configuration.ServiceConfiguration) StageLogEntity(pipelite.entity.StageLogEntity) StageLogEntity(pipelite.entity.StageLogEntity) Stage(pipelite.stage.Stage)

Example 18 with Process

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);
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Stage(pipelite.stage.Stage) RegisteredPipeline(pipelite.RegisteredPipeline) Process(pipelite.process.Process)

Example 19 with Process

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) -> {
        });
    });
}
Also used : Process(pipelite.process.Process)

Example 20 with Process

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);
        });
    });
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Schedule(pipelite.Schedule) Process(pipelite.process.Process) ScheduleEntity(pipelite.entity.ScheduleEntity)

Aggregations

Process (pipelite.process.Process)40 Test (org.junit.jupiter.api.Test)29 Stage (pipelite.stage.Stage)27 ProcessBuilder (pipelite.process.builder.ProcessBuilder)24 ProcessEntity (pipelite.entity.ProcessEntity)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 StageState (pipelite.stage.StageState)14 StageEntity (pipelite.entity.StageEntity)8 StageLogEntity (pipelite.entity.StageLogEntity)4 ArrayList (java.util.ArrayList)3 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)3 ZonedDateTime (java.time.ZonedDateTime)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RegisteredPipeline (pipelite.RegisteredPipeline)2 ScheduleEntity (pipelite.entity.ScheduleEntity)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 PipelineMetrics (pipelite.metrics.PipelineMetrics)2 ProcessState (pipelite.process.ProcessState)2 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)2