Search in sources :

Example 1 with TaskRun

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"));
}
Also used : TaskRun(io.kestra.core.models.executions.TaskRun) Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 2 with TaskRun

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)));
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) TaskRun(io.kestra.core.models.executions.TaskRun) java.util(java.util) InputsTest(io.kestra.core.runners.InputsTest) QueueInterface(io.kestra.core.queues.QueueInterface) TimeoutException(java.util.concurrent.TimeoutException) Client(io.micronaut.http.client.annotation.Client) RxHttpClient(io.micronaut.rxjava2.http.client.RxHttpClient) State(io.kestra.core.models.flows.State) IdUtils(io.kestra.core.utils.IdUtils) Event(io.micronaut.http.sse.Event) RxSseClient(io.micronaut.rxjava2.http.client.sse.RxSseClient) HttpStatus(io.micronaut.http.HttpStatus) MediaType(io.micronaut.http.MediaType) Duration(java.time.Duration) HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) Argument(io.micronaut.core.type.Argument) HttpRequest(io.micronaut.http.HttpRequest) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Webhook(io.kestra.core.models.triggers.types.Webhook) MultipartBody(io.micronaut.http.client.multipart.MultipartBody) PagedResults(io.kestra.webserver.responses.PagedResults) ImmutableMap(com.google.common.collect.ImmutableMap) QueueFactoryInterface(io.kestra.core.queues.QueueFactoryInterface) Rethrow.throwRunnable(io.kestra.core.utils.Rethrow.throwRunnable) Matchers(org.hamcrest.Matchers) Execution(io.kestra.core.models.executions.Execution) File(java.io.File) Test(org.junit.jupiter.api.Test) EmbeddedServer(io.micronaut.runtime.server.EmbeddedServer) FileMetas(io.kestra.core.models.storage.FileMetas) Flow(io.kestra.core.models.flows.Flow) Inject(jakarta.inject.Inject) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) Named(jakarta.inject.Named) Execution(io.kestra.core.models.executions.Execution) Flow(io.kestra.core.models.flows.Flow) InputsTest(io.kestra.core.runners.InputsTest) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 3 with TaskRun

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());
}
Also used : FlowableTask(io.kestra.core.models.tasks.FlowableTask) TaskRun(io.kestra.core.models.executions.TaskRun) NextTaskRun(io.kestra.core.models.executions.NextTaskRun) InternalException(io.kestra.core.exceptions.InternalException)

Example 4 with TaskRun

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");
}
Also used : TaskRun(io.kestra.core.models.executions.TaskRun) NextTaskRun(io.kestra.core.models.executions.NextTaskRun) ArrayList(java.util.ArrayList)

Example 5 with TaskRun

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));
}
Also used : TaskRun(io.kestra.core.models.executions.TaskRun) Task(io.kestra.core.models.tasks.Task) Execution(io.kestra.core.models.executions.Execution) Flow(io.kestra.core.models.flows.Flow) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TaskRun (io.kestra.core.models.executions.TaskRun)23 Execution (io.kestra.core.models.executions.Execution)14 Flow (io.kestra.core.models.flows.Flow)9 State (io.kestra.core.models.flows.State)8 Test (org.junit.jupiter.api.Test)6 NextTaskRun (io.kestra.core.models.executions.NextTaskRun)5 Task (io.kestra.core.models.tasks.Task)5 Inject (jakarta.inject.Inject)5 java.util (java.util)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 TaskRunAttempt (io.kestra.core.models.executions.TaskRunAttempt)4 FlowableTask (io.kestra.core.models.tasks.FlowableTask)4 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)4 Duration (java.time.Duration)4 InternalException (io.kestra.core.exceptions.InternalException)3 QueueFactoryInterface (io.kestra.core.queues.QueueFactoryInterface)3 QueueInterface (io.kestra.core.queues.QueueInterface)3 FlowRepositoryInterface (io.kestra.core.repositories.FlowRepositoryInterface)3 TimeoutExceededException (io.kestra.core.exceptions.TimeoutExceededException)2 MetricRegistry (io.kestra.core.metrics.MetricRegistry)2