Sub-DAGs and Fan-out
A step can run another workflow as a sub-DAG. The child is a full run with its own steps, logs, and status. Use sub-DAGs to reuse a workflow, or to run one workflow once per item in a list.
The workflow
bash
curl -fsSLO https://docs.dagu.sh/tutorial/dags/tutorial-07-sub-dags.yamlyaml
# Dagu tutorial, lesson 7: https://docs.dagu.sh/tutorial/sub-dags
description: Call a child workflow, then fan it out across regions
type: graph
steps:
- id: build
action: dag.run
with:
dag: build-app
params:
version: "1.4.0"
- id: smoke_test
action: dag.run
with:
dag: smoke-test
params:
region: ${ITEM}
bundle: ${steps.build.outputs.bundle}
parallel:
items: [us-east, eu-west, ap-south]
max_concurrent: 2
depends: build
- id: announce
run: echo "Released ${steps.build.outputs.bundle} to 3 regions"
depends: smoke_test
---
name: build-app
type: graph
params:
- name: version
type: string
required: true
steps:
- id: compile
run: sleep 1 && echo "app-${params.version}.tar.gz"
output:
bundle:
from: stdout
- id: publish
action: outputs.write
with:
values:
bundle: ${steps.compile.outputs.bundle}
depends: compile
---
name: smoke-test
type: graph
params:
- name: region
type: string
required: true
- name: bundle
type: string
required: true
steps:
- id: check
run: sleep 1 && echo "${params.bundle} is healthy in ${params.region}"The file holds three workflows separated by ---. The first is the parent. build-app and smoke-test are children, named with name.
action: dag.runruns the child named indag.paramspasses values into it. A child sees only what it receives this way, not the parent's environment.outputs.writeinbuild-appreturnsbundleto the parent, which reads it as${steps.build.outputs.bundle}.parallelrunssmoke-testonce per item, at most 2 at a time.${ITEM}is the current item.
Watch it run
announcerunSucceeded
Released app-1.4.0.tar.gz to 3 regions
Select smoke_test to see the three child runs it started, one per region.
Run it yourself
bash
dagu start tutorial-07-sub-dags.yamlIn the Web UI, the Activity list marks smoke_test with 3 sub-runs. Select it to see, on the Log tab, a JSON summary of each child run's status and outputs.
A child can also live in its own file. Then dag names that file, for example dag: smoke-test for smoke-test.yaml in the same folder.
Try it
- Add
ap-easttoitems. How many child runs doessmoke_teststart? - Change
max_concurrent: 2to1. How long doessmoke_testtake now?
Answers
- Four, one per item.
- About 3 seconds instead of 2. The child runs no longer overlap: each starts after the previous one finishes.

