use of io.kestra.core.models.executions.TaskRun in project kestra by kestra-io.
the class EachSequentialTest method eachSwitch.
@Test
void eachSwitch() throws TimeoutException, InternalException {
Execution execution = runnerUtils.runOne("io.kestra.tests", "each-switch");
assertThat(execution.getTaskRunList(), hasSize(12));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
TaskRun switchNumber1 = execution.findTaskRunByTaskIdAndValue("2-1-1_switch-number-1", Arrays.asList("b", "1"));
assertThat((String) switchNumber1.getOutputs().get("value"), is("1"));
TaskRun switchNumber2 = execution.findTaskRunByTaskIdAndValue("2-1-1_switch-number-2", Arrays.asList("b", "2"));
assertThat((String) switchNumber2.getOutputs().get("value"), is("2 b"));
}
use of io.kestra.core.models.executions.TaskRun in project kestra by kestra-io.
the class ExecutionControllerTest method restartFromTaskId.
@Test
void restartFromTaskId() throws Exception {
final String flowId = "restart_with_inputs";
final String referenceTaskId = "instant";
// Run execution until it ends
Execution parentExecution = runnerUtils.runOne(TESTS_FLOW_NS, flowId, null, (flow, execution1) -> runnerUtils.typedInputs(flow, execution1, inputs));
Optional<Flow> flow = flowRepositoryInterface.findById(TESTS_FLOW_NS, flowId);
assertThat(flow.isPresent(), is(true));
// Run child execution starting from a specific task and wait until it finishes
Execution finishedChildExecution = runnerUtils.awaitChildExecution(flow.get(), parentExecution, throwRunnable(() -> {
Thread.sleep(100);
Execution createdChidExec = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/" + parentExecution.getId() + "/replay?taskRunId=" + parentExecution.findTaskRunByTaskIdAndValue(referenceTaskId, List.of()).getId(), ImmutableMap.of()), Execution.class);
assertThat(createdChidExec, notNullValue());
assertThat(createdChidExec.getParentId(), is(parentExecution.getId()));
assertThat(createdChidExec.getTaskRunList().size(), is(4));
assertThat(createdChidExec.getState().getCurrent(), is(State.Type.RESTARTED));
IntStream.range(0, 3).mapToObj(value -> createdChidExec.getTaskRunList().get(value)).forEach(taskRun -> assertThat(taskRun.getState().getCurrent(), is(State.Type.SUCCESS)));
assertThat(createdChidExec.getTaskRunList().get(3).getState().getCurrent(), is(State.Type.RESTARTED));
assertThat(createdChidExec.getTaskRunList().get(3).getAttempts().size(), is(1));
}), Duration.ofSeconds(15));
assertThat(finishedChildExecution, notNullValue());
assertThat(finishedChildExecution.getParentId(), is(parentExecution.getId()));
assertThat(finishedChildExecution.getTaskRunList().size(), is(5));
finishedChildExecution.getTaskRunList().stream().map(TaskRun::getState).forEach(state -> assertThat(state.getCurrent(), is(State.Type.SUCCESS)));
}
use of io.kestra.core.models.executions.TaskRun in project kestra by kestra-io.
the class ExecutorService method saveFlowableOutput.
private List<TaskRun> saveFlowableOutput(List<NextTaskRun> nextTaskRuns, Executor executor, TaskRun parentTaskRun) {
return nextTaskRuns.stream().map(throwFunction(t -> {
TaskRun taskRun = t.getTaskRun();
if (!(t.getTask() instanceof FlowableTask)) {
return taskRun;
}
FlowableTask<?> flowableTask = (FlowableTask<?>) t.getTask();
try {
RunContext runContext = runContextFactory.of(executor.getFlow(), t.getTask(), executor.getExecution(), t.getTaskRun());
taskRun = taskRun.withOutputs(flowableTask.outputs(runContext, executor.getExecution(), parentTaskRun) != null ? flowableTask.outputs(runContext, executor.getExecution(), parentTaskRun).toMap() : ImmutableMap.of());
} catch (Exception e) {
executor.getFlow().logger().warn("Unable to save output on taskRun '{}'", taskRun, e);
}
return taskRun;
})).collect(Collectors.toList());
}
use of io.kestra.core.models.executions.TaskRun in project kestra by kestra-io.
the class ExecutorService method handleChildWorkerTaskResult.
private Executor handleChildWorkerTaskResult(Executor executor) throws InternalException {
if (executor.getExecution().getTaskRunList() == null) {
return executor;
}
List<WorkerTaskResult> list = new ArrayList<>();
for (TaskRun taskRun : executor.getExecution().getTaskRunList()) {
if (taskRun.getState().isRunning()) {
Optional<WorkerTaskResult> workerTaskResult = this.childWorkerTaskResult(executor.getFlow(), executor.getExecution(), taskRun);
workerTaskResult.ifPresent(list::add);
}
}
if (list.size() == 0) {
return executor;
}
return executor.withWorkerTaskResults(list, "handleChildWorkerTaskResult");
}
use of io.kestra.core.models.executions.TaskRun in project kestra by kestra-io.
the class KafkaExecutorTest method concurrent.
@Test
void concurrent() {
startStream(this.executorStore);
Flow flow = flowRepository.findById("io.kestra.tests", "logs").orElseThrow();
this.flowInput().pipeInput(flow.uid(), flow);
startStream(this.executorMain);
Execution execution = createExecution(flow);
// task
execution = runningAndSuccessSequential(flow, execution, 0);
execution = runningAndSuccessSequential(flow, execution, 1);
// next
// TestRecord<String, Execution> executionRecord = executionOutput().readRecord();
assertThat(execution.getTaskRunList(), hasSize(3));
assertThat(execution.getTaskRunList().get(2).getState().getCurrent(), is(State.Type.CREATED));
Task task = flow.getTasks().get(2);
TaskRun taskRun = execution.getTaskRunList().get(2);
// concurrent
this.changeStatus(task, taskRun, State.Type.RUNNING);
this.changeStatus(task, taskRun, State.Type.SUCCESS);
execution = executionOutput().readRecord().getValue();
execution = executionOutput().readRecord().getValue();
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}
Aggregations