Skip to content

Commit

Permalink
docs: add nested loop example (#6948)
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-geller authored Jan 26, 2025
1 parent 4f96f81 commit 34751cf
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/src/main/java/io/kestra/plugin/core/flow/ForEach.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,61 @@
- sleep {{ parent.taskrun.value }}
"""
),
@Example(
full = true,
title = """
This example demonstrates processing data across nested loops of S3 buckets, years, and months. \
It generates structured identifiers (e.g., `bucket1_2025_March`) by combining values from each loop level, \
while accessing parent loop values like years and buckets, which can be useful for partitioned \
storage paths or time-based datasets. The flow uses dynamic expressions referencing parent context.""",
code = """
id: loop_multiple_times
namespace: company.team
inputs:
- id: s3_buckets
type: ARRAY
itemType: STRING
defaults:
- bucket1
- bucket2
- id: years
type: ARRAY
itemType: INT
defaults:
- 2025
- 2026
- id: months
type: ARRAY
itemType: STRING
defaults:
- March
- April
tasks:
- id: buckets
type: io.kestra.plugin.core.flow.ForEach
values: "{{inputs.s3_buckets}}"
tasks:
- id: year
type: io.kestra.plugin.core.flow.ForEach
values: "{{inputs.years}}"
tasks:
- id: month
type: io.kestra.plugin.core.flow.ForEach
values: "{{inputs.months}}"
tasks:
- id: full_table_name
type: io.kestra.plugin.core.log.Log
message: |
Full table name: {{parents[1].taskrun.value }}_{{parent.taskrun.value}}_{{taskrun.value}}
Direct/current loop (months): {{taskrun.value}}
Value of loop one higher up (years): {{parents[0].taskrun.value}}
Further up (table types): {{parents[1].taskrun.value}}
"""
),
}
)
public class ForEach extends Sequential implements FlowableTask<VoidOutput> {
Expand Down

0 comments on commit 34751cf

Please sign in to comment.