Skip to content

Commit

Permalink
feat(script): include task null outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Dec 17, 2024
1 parent aa8588c commit b133210
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.core.models.executions;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.kestra.core.models.TenantInterface;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.tasks.ResolvedTask;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class TaskRun implements TenantInterface {
List<TaskRunAttempt> attempts;

@With
@JsonInclude(JsonInclude.Include.ALWAYS) // always include outputs so it's easier to reason about in expressions
Map<String, Object> outputs;

@NotNull
Expand Down
47 changes: 47 additions & 0 deletions core/src/test/java/io/kestra/core/runners/NullOutputTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.kestra.core.runners;

import io.kestra.core.junit.annotations.KestraTest;
import io.kestra.core.junit.extensions.LoadFlows;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.flows.State;
import io.kestra.core.queues.QueueException;
import io.kestra.core.utils.TestsUtils;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

@KestraTest
public class NullOutputTest {
@Inject
protected StandAloneRunner runner;

@Inject
protected RunnerUtils runnerUtils;

@BeforeEach
protected void init() throws IOException, URISyntaxException {
if (!runner.isRunning()) {
runner.run();
}
}

@Test
@LoadFlows("flows/valids/null-output.yaml")
void shouldIncludeNullOutput() throws QueueException, TimeoutException {
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "null-output");

assertThat(execution, notNullValue());
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
assertThat(execution.getTaskRunList(), hasSize(1));
assertThat(execution.getTaskRunList().getFirst().getOutputs(), aMapWithSize(1));
assertThat(execution.getTaskRunList().getFirst().getOutputs().containsKey("value"), is(true));
}
}
30 changes: 30 additions & 0 deletions core/src/test/java/io/kestra/core/tasks/test/NullOutputTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.kestra.core.tasks.test;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.runners.RunContext;
import lombok.*;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Plugin
public class NullOutputTask extends Task implements RunnableTask<NullOutputTask.Output> {

@Override
public Output run(RunContext runContext) throws Exception {
return Output.builder().build();
}

@Builder
@Getter
public static class Output implements io.kestra.core.models.tasks.Output {
@JsonInclude(JsonInclude.Include.ALWAYS)
private String value;
}
}
6 changes: 6 additions & 0 deletions core/src/test/resources/flows/valids/null-output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id: null-output
namespace: io.kestra.tests

tasks:
- id: null-output
type: io.kestra.core.tasks.test.NullOutputTask
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.plugin.scripts.exec.scripts.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.tasks.Output;
Expand All @@ -19,6 +20,7 @@ public class ScriptOutput implements Output {
@Schema(
title = "The value extracted from the output of the executed `commands`."
)
@JsonInclude(JsonInclude.Include.ALWAYS) // always include vars so it's easier to reason about in expressions
private final Map<String, Object> vars;

@Schema(
Expand Down

0 comments on commit b133210

Please sign in to comment.