-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
from airflow.models import DagBag | ||
from collections import defaultdict | ||
import sys | ||
import os, sys | ||
|
||
|
||
def dump_dags(outfile): | ||
def dump_dags(output_base_path): | ||
os.mkdirs(output_base_path, exist_ok=True) | ||
bag = DagBag() | ||
for dag_id in sorted(bag.dag_ids): | ||
dag = bag.get_dag(dag_id) | ||
outfile.write(f'== {dag_id} ==\n\n') | ||
|
||
adj = defaultdict(list) # Adjacency list of DAG. | ||
for task in dag.tasks: | ||
for upstream_task_id in task.upstream_task_ids: | ||
adj[upstream_task_id].append(task.task_id) | ||
with open(os.path.join(output_base_path, dag_id), 'w') as outfile: | ||
adj = defaultdict(list) # Adjacency list of DAG. | ||
for task in dag.tasks: | ||
for upstream_task_id in task.upstream_task_ids: | ||
adj[upstream_task_id].append(task.task_id) | ||
|
||
for task_id in sorted(dag.task_ids): | ||
task = dag.get_task(task_id) | ||
outfile.write(f'{task_id}\n') | ||
for child_task_id in sorted(adj[task_id]): | ||
outfile.write(f' -> {child_task_id}\n') | ||
outfile.write('\n') | ||
for task_id in sorted(dag.task_ids): | ||
task = dag.get_task(task_id) | ||
outfile.write(f'{task_id}\n') | ||
for child_task_id in sorted(adj[task_id]): | ||
outfile.write(f' -> {child_task_id}\n') | ||
outfile.write('\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 2: | ||
print('Usage: dump_dags.py <output filename>') | ||
print('Usage: dump_dags.py <output base path>') | ||
sys.exit(1) | ||
with open(sys.argv[1], 'w') as outfile: | ||
dump_dags(outfile) | ||
dump_dags(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters