Search in sources :

Example 16 with ProcessEntity

use of pipelite.entity.ProcessEntity in project pipelite by enasequence.

the class ProcessService method endExecution.

/**
 * Called when the process execution ends. Sets the process state and the execution end time.
 * Increases the process execution count. Saves the process.
 *
 * @param process the process
 * @param processState the process state
 */
@Timed("pipelite.transactional")
public ProcessEntity endExecution(Process process, ProcessState processState) {
    ProcessEntity processEntity = process.getProcessEntity();
    processEntity.endExecution(processState);
    ProcessEntity savedProcess = saveProcess(processEntity);
    mailService.sendProcessExecutionMessage(process);
    return savedProcess;
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Timed(io.micrometer.core.annotation.Timed)

Example 17 with ProcessEntity

use of pipelite.entity.ProcessEntity 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);
    }
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity)

Example 18 with ProcessEntity

use of pipelite.entity.ProcessEntity in project pipelite by enasequence.

the class MailService method getProcessExecutionSubject.

String getProcessExecutionSubject(Process process) {
    ProcessEntity processEntity = process.getProcessEntity();
    String state = "";
    if (processEntity.getProcessState() != null) {
        state = processEntity.getProcessState().name();
    }
    return "Pipelite process (" + state + "): " + processEntity.getPipelineName() + "/" + process.getProcessId();
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity)

Example 19 with ProcessEntity

use of pipelite.entity.ProcessEntity in project pipelite by enasequence.

the class ProcessEntityCreator method create.

/**
 * Creates and saves a process entity.
 *
 * @param processService the process service
 * @param pipelineName the pipeline name
 * @param process the process for which the process entity is created
 * @return the created process entity or null if it could not be created
 */
public static ProcessEntity create(ProcessService processService, String pipelineName, Pipeline.Process process) {
    String processId = process.getProcessId();
    if (processId == null || processId.trim().isEmpty()) {
        throw new PipeliteException("Failed to create process: missing process id");
    }
    ProcessEntity processEntity;
    String trimmedProcessId = processId.trim();
    Optional<ProcessEntity> savedProcessEntity = processService.getSavedProcess(pipelineName, trimmedProcessId);
    if (savedProcessEntity.isPresent()) {
        // Process entity already exists
        processEntity = savedProcessEntity.get();
    } else {
        processEntity = processService.createExecution(pipelineName, trimmedProcessId, process.getPriority().getInt());
        if (processEntity == null) {
            throw new RuntimeException("Failed to create process: " + trimmedProcessId);
        }
    }
    return processEntity;
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) PipeliteException(pipelite.exception.PipeliteException)

Example 20 with ProcessEntity

use of pipelite.entity.ProcessEntity in project pipelite by enasequence.

the class ProcessEntityCreator method create.

/**
 * Creates and saves process entities.
 *
 * @param processCnt the number of process entities to create
 * @return the number of created process entities
 */
public int create(int processCnt) {
    if (pipeline == null) {
        return 0;
    }
    int createCnt = 0;
    logContext(log.atInfo()).log("Creating new processes");
    while (processCnt-- > 0) {
        Pipeline.Process process = pipeline.nextProcess();
        if (process == null) {
            return createCnt;
        }
        ProcessEntity processEntity = create(processService, pipelineName, process);
        if (processEntity != null) {
            pipeline.confirmProcess(processEntity.getProcessId());
            createCnt++;
        }
    }
    logContext(log.atInfo()).log("Created " + createCnt + " new processes");
    return createCnt;
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Pipeline(pipelite.Pipeline)

Aggregations

ProcessEntity (pipelite.entity.ProcessEntity)39 Test (org.junit.jupiter.api.Test)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Process (pipelite.process.Process)14 ProcessBuilder (pipelite.process.builder.ProcessBuilder)10 ScheduleEntity (pipelite.entity.ScheduleEntity)8 Stage (pipelite.stage.Stage)8 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)4 ZonedDateTime (java.time.ZonedDateTime)3 Pipeline (pipelite.Pipeline)3 StageEntity (pipelite.entity.StageEntity)3 StageLogEntity (pipelite.entity.StageLogEntity)3 PipeliteException (pipelite.exception.PipeliteException)2 Timed (io.micrometer.core.annotation.Timed)1 ArrayList (java.util.ArrayList)1 ProcessInfo (pipelite.controller.api.info.ProcessInfo)1 ProcessState (pipelite.process.ProcessState)1 ProcessRunner (pipelite.runner.process.ProcessRunner)1 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)1 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)1