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

Feats docs(loops) : updated loop over a list of values #1888

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fix: eachsequential -> foreach
  • Loading branch information
wrussell1999 authored Dec 4, 2024
commit 24f193d073ab482d76c6b033cdc354212886447c
18 changes: 9 additions & 9 deletions content/docs/15.how-to-guides/loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ topics:

How to iterate over a list of values in your flow.

In this guide, you will learn how to iterate over a list of values using the `EachSequential` task. This task enables you to loop through a list of values and execute specific tasks for each value in the list. This approach is useful for scenarios where multiple similar tasks need to be run for different inputs.
In this guide, you will learn how to iterate over a list of values using the `ForEach` task. This task enables you to loop through a list of values and execute specific tasks for each value in the list. This approach is useful for scenarios where multiple similar tasks need to be run for different inputs.

## Prerequisites

Expand All @@ -19,23 +19,23 @@ Before you begin:

## Loop Over Nested Lists of Values

This example demonstrates how to use `EachSequential` to loop over a list of strings and then loop through a nested list for each string. To see the flow in action, define the `each_nested` flow as shown below:
This example demonstrates how to use `ForEach` to loop over a list of strings and then loop through a nested list for each string. To see the flow in action, define the `each_nested` flow as shown below:

```yaml
id: each_nested
namespace: company.team

tasks:
- id: 1_each
type: io.kestra.plugin.core.flow.EachSequential
value: '["s1", "s2", "s3"]'
type: io.kestra.plugin.core.flow.ForEach
values: '["s1", "s2", "s3"]'
tasks:
- id: 1-1_return
type: io.kestra.plugin.core.debug.Return
format: "{{task.id}} > {{taskrun.value}} > {{taskrun.startDate}}"
- id: 1-2_each
type: io.kestra.plugin.core.flow.EachSequential
value: '["a a", "b b"]'
type: io.kestra.plugin.core.flow.ForEach
values: '["a a", "b b"]'
tasks:
- id: 1-2-1_return
type: io.kestra.plugin.core.debug.Return
Expand All @@ -57,7 +57,7 @@ The above flow, when executed, iterates over a nested list of values, logging me

Within the flow:

- `1_each`: Uses the `EachSequential` task to iterate over the list `["s1", "s2", "s3"]`. For each value, it runs the nested tasks defined within.
- `1_each`: Uses the `ForEach` task to iterate over the list `["s1", "s2", "s3"]`. For each value, it runs the nested tasks defined within.

- `1-1_return`: Logs the task ID, the current list value, and the task run start time.

Expand All @@ -74,10 +74,10 @@ Within the flow:

## Next Steps

Now that you've seen how to loop over a list of values using `EachSequential`, you can apply this technique to any scenario where multiple iterations of similar tasks are needed. You can further extend this flow by:
Now that you've seen how to loop over a list of values using `ForEach`, you can apply this technique to any scenario where multiple iterations of similar tasks are needed. You can further extend this flow by:
- Adding more complex nested loops.
- Using dynamic input values instead of hardcoded lists.
- Logging or processing additional data from each iteration.

For more advanced use cases, refer to Kestra’s official [EachSequential](https://kestra.io/plugins/core/tasks/flow/io.kestra.plugin.core.flow.eachsequential) task documentation.
For more advanced use cases, refer to Kestra’s official [ForEach](https://kestra.io/plugins/core/tasks/flow/io.kestra.plugin.core.flow.foreach) task documentation.