Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Rename WaitFor task to LoopUntil #6978

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.kestra.core.utils.TruthUtils;
import io.kestra.plugin.core.flow.Pause;
import io.kestra.plugin.core.flow.Subflow;
import io.kestra.plugin.core.flow.WaitFor;
import io.kestra.plugin.core.flow.LoopUntil;
import io.kestra.plugin.core.flow.WorkingDirectory;
import io.micronaut.context.ApplicationContext;
import io.opentelemetry.api.OpenTelemetry;
Expand Down Expand Up @@ -562,7 +562,7 @@ else if (parentTask != null && parentTask.getRetry() != null) {
}
}
// WaitFor case
else if (task instanceof WaitFor waitFor && taskRun.getState().isRunning()) {
else if (task instanceof LoopUntil waitFor && taskRun.getState().isRunning()) {
if (waitFor.childTaskRunExecuted(executor.getExecution(), taskRun)) {
Output newOutput = waitFor.outputs(taskRun);
TaskRun updatedTaskRun = taskRun.withOutputs(newOutput.toMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@
full = true,
title = "Run a task until it returns a specific value. Note how you don't need to take care of incrementing the iteration count. The task will loop and keep track of the iteration outputs behind the scenes — you only need to specify the exit condition for the loop.",
code = """
id: wait_for
id: loop_until
namespace: company.team

tasks:
- id: loop
type: io.kestra.plugin.core.flow.WaitFor
type: io.kestra.plugin.core.flow.LoopUntil
condition: "{{ outputs.return.value == '4' }}"
tasks:
- id: return
type: io.kestra.plugin.core.debug.Return
format: "{{ outputs.loop.iterationCount }}"
"""
)
}
},
aliases = "io.kestra.plugin.core.flow.WaitFor"
)
public class WaitFor extends Task implements FlowableTask<WaitFor.Output> {
public class LoopUntil extends Task implements FlowableTask<LoopUntil.Output> {
private static final int INITIAL_LOOP_VALUE = 1;

@Valid
Expand Down Expand Up @@ -232,17 +233,17 @@ public boolean childTaskRunExecuted(Execution execution, TaskRun parentTaskRun)

@SuppressWarnings("unchecked")
@Override
public WaitFor.Output outputs(RunContext runContext) throws IllegalVariableEvaluationException {
public LoopUntil.Output outputs(RunContext runContext) throws IllegalVariableEvaluationException {
Map<String, Object> outputs = (Map<String, Object>) runContext.getVariables().get("outputs");
if (outputs != null && outputs.get(this.id) != null) {
return Output.builder().iterationCount((Integer) ((Map<String, Object>) outputs.get(this.id)).get("iterationCount")).build();
}
return WaitFor.Output.builder()
return LoopUntil.Output.builder()
.iterationCount(INITIAL_LOOP_VALUE)
.build();
}

public WaitFor.Output outputs(TaskRun parentTaskRun) throws IllegalVariableEvaluationException {
public LoopUntil.Output outputs(TaskRun parentTaskRun) throws IllegalVariableEvaluationException {
String value = parentTaskRun != null ?
String.valueOf(Optional.ofNullable(parentTaskRun.getOutputs())
.map(outputs -> outputs.get("iterationCount"))
Expand Down
Loading