Search in sources :

Example 1 with StageExecutorResultCallback

use of pipelite.stage.executor.StageExecutorResultCallback in project pipelite by enasequence.

the class StageRunner method executeStage.

private void executeStage(StageExecutorResultCallback processRunnerResultCallback) {
    StageExecutorResultCallback stageRunnerResultCallback = (executorResult) -> internalErrorHandler.execute(() -> {
        if (executorResult == null) {
            throw new PipeliteException("Missing executor result");
        }
        if (executorResult.isSubmitted()) {
            logContext(log.atFine()).log("Submitted asynchronous stage execution");
            pipeliteServices.stage().saveStage(stage);
        } else if (executorResult.isActive()) {
            if (ZonedDateTime.now().isAfter(timeout)) {
                logContext(log.atSevere()).log("Maximum stage execution time exceeded.");
                // Terminate executor.
                internalErrorHandler.execute(() -> stage.getExecutor().terminate());
                endStageExecution(processRunnerResultCallback, StageExecutorResult.timeoutError());
            } else {
                logContext(log.atFiner()).log("Waiting asynchronous stage execution to complete");
            }
        } else if (executorResult.isSuccess() || executorResult.isError()) {
            endStageExecution(processRunnerResultCallback, executorResult);
        }
    }, (ex) -> endStageExecution(processRunnerResultCallback, StageExecutorResult.internalError(ex)));
    executeStage(processRunnerResultCallback, stageRunnerResultCallback);
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) PipeliteMetrics(pipelite.metrics.PipeliteMetrics) StageExecutorResult(pipelite.stage.executor.StageExecutorResult) InternalErrorHandler(pipelite.error.InternalErrorHandler) ZonedDateTime(java.time.ZonedDateTime) LogKey(pipelite.log.LogKey) StageExecutor(pipelite.stage.executor.StageExecutor) StageExecutorSerializer(pipelite.stage.executor.StageExecutorSerializer) StageExecutorResultCallback(pipelite.stage.executor.StageExecutorResultCallback) PipeliteException(pipelite.exception.PipeliteException) Process(pipelite.process.Process) AbstractAsyncExecutor(pipelite.executor.AbstractAsyncExecutor) PipeliteServices(pipelite.service.PipeliteServices) Stage(pipelite.stage.Stage) Flogger(lombok.extern.flogger.Flogger) Duration(java.time.Duration) FluentLogger(com.google.common.flogger.FluentLogger) Assert(org.springframework.util.Assert) StageExecutorResultCallback(pipelite.stage.executor.StageExecutorResultCallback) PipeliteException(pipelite.exception.PipeliteException)

Aggregations

FluentLogger (com.google.common.flogger.FluentLogger)1 Duration (java.time.Duration)1 ZonedDateTime (java.time.ZonedDateTime)1 Flogger (lombok.extern.flogger.Flogger)1 Assert (org.springframework.util.Assert)1 InternalErrorHandler (pipelite.error.InternalErrorHandler)1 PipeliteException (pipelite.exception.PipeliteException)1 AbstractAsyncExecutor (pipelite.executor.AbstractAsyncExecutor)1 LogKey (pipelite.log.LogKey)1 PipeliteMetrics (pipelite.metrics.PipeliteMetrics)1 Process (pipelite.process.Process)1 PipeliteServices (pipelite.service.PipeliteServices)1 Stage (pipelite.stage.Stage)1 StageExecutor (pipelite.stage.executor.StageExecutor)1 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)1 StageExecutorResultCallback (pipelite.stage.executor.StageExecutorResultCallback)1 StageExecutorSerializer (pipelite.stage.executor.StageExecutorSerializer)1 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)1