use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class ExecutionService method mapTaskRun.
private TaskRun mapTaskRun(Flow flow, TaskRun originalTaskRun, Map<String, String> mappingTaskRunId, String newExecutionId, State.Type newStateType, Boolean toRestart) throws InternalException {
boolean isFlowable = flow.findTaskByTaskId(originalTaskRun.getTaskId()).isFlowable();
State alterState;
if (!isFlowable) {
// The current task run is the reference task run, its default state will be newState
alterState = originalTaskRun.withState(newStateType).getState();
} else {
// The current task run is an ascendant of the reference task run
alterState = originalTaskRun.withState(State.Type.RUNNING).getState();
}
return originalTaskRun.forChildExecution(mappingTaskRunId, newExecutionId, toRestart ? alterState : null);
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class Worker method runAttempt.
private WorkerTask runAttempt(WorkerTask workerTask) {
RunnableTask<?> task = (RunnableTask<?>) workerTask.getTask();
RunContext runContext = workerTask.getRunContext().forWorker(this.applicationContext, workerTask.getTaskRun());
Logger logger = runContext.logger();
TaskRunAttempt.TaskRunAttemptBuilder builder = TaskRunAttempt.builder().state(new State().withState(State.Type.RUNNING));
AtomicInteger metricRunningCount = getMetricRunningCount(workerTask);
metricRunningCount.incrementAndGet();
WorkerThread workerThread = new WorkerThread(logger, workerTask, task, runContext, metricRegistry);
workerThread.start();
// emit attempts
this.workerTaskResultQueue.emit(new WorkerTaskResult(workerTask.withTaskRun(workerTask.getTaskRun().withAttempts(this.addAttempt(workerTask, builder.build())))));
// run it
State.Type state;
try {
synchronized (this) {
workerThreadReferences.add(workerThread);
}
workerThread.join();
state = workerThread.getTaskState();
} catch (InterruptedException e) {
logger.error("Failed to join WorkerThread {}", e.getMessage(), e);
state = State.Type.FAILED;
} finally {
synchronized (this) {
workerThreadReferences.remove(workerThread);
}
}
metricRunningCount.decrementAndGet();
// attempt
TaskRunAttempt taskRunAttempt = builder.metrics(runContext.metrics()).build().withState(state);
// logs
if (workerThread.getTaskOutput() != null) {
log.debug("Outputs\n{}", JacksonMapper.log(workerThread.getTaskOutput()));
}
if (runContext.metrics().size() > 0) {
log.trace("Metrics\n{}", JacksonMapper.log(runContext.metrics()));
}
// save outputs
List<TaskRunAttempt> attempts = this.addAttempt(workerTask, taskRunAttempt);
TaskRun taskRun = workerTask.getTaskRun().withAttempts(attempts);
try {
taskRun = taskRun.withOutputs(workerThread.getTaskOutput() != null ? workerThread.getTaskOutput().toMap() : ImmutableMap.of());
} catch (Exception e) {
logger.warn("Unable to save output on taskRun '{}'", taskRun, e);
}
return workerTask.withTaskRun(taskRun);
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class ExecutionTest method hasTaskRunJoinableRestartSuccess.
@Test
void hasTaskRunJoinableRestartSuccess() {
Execution execution = Execution.builder().taskRunList(Collections.singletonList(TASK_RUN.state(new State(State.Type.CREATED, new State().withState(State.Type.RUNNING).withState(State.Type.SUCCESS))).build())).build();
assertThat(execution.hasTaskRunJoinable(TASK_RUN.state(new State(State.Type.SUCCESS, new State().withState(State.Type.RUNNING).withState(State.Type.SUCCESS))).build()), is(true));
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class ExecutionTest method hasTaskRunJoinableTrue.
@Test
void hasTaskRunJoinableTrue() {
Execution execution = Execution.builder().taskRunList(Collections.singletonList(TASK_RUN.state(new State(State.Type.RUNNING, new State())).build())).build();
assertThat(execution.hasTaskRunJoinable(TASK_RUN.state(new State(State.Type.FAILED, new State().withState(State.Type.RUNNING))).build()), is(true));
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class ExecutionTest method hasTaskRunJoinableRestartFailed.
@Test
void hasTaskRunJoinableRestartFailed() {
Execution execution = Execution.builder().taskRunList(Collections.singletonList(TASK_RUN.state(new State(State.Type.CREATED, new State().withState(State.Type.RUNNING).withState(State.Type.FAILED))).build())).build();
assertThat(execution.hasTaskRunJoinable(TASK_RUN.state(new State(State.Type.FAILED, new State().withState(State.Type.RUNNING))).build()), is(false));
}
Aggregations