Skip to content

Instantly share code, notes, and snippets.

@pingzh
Created June 10, 2022 18:07
Show Gist options
  • Save pingzh/cb9bc9d9c9b48c301b5ea1fc314c9b70 to your computer and use it in GitHub Desktop.
Save pingzh/cb9bc9d9c9b48c301b5ea1fc314c9b70 to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow.operators.dummy import DummyOperator
with DAG(
dag_id='00_ping_test_2',
schedule_interval='@daily',
start_date=datetime(2022, 1, 1),
catchup=True,
dagrun_timeout=timedelta(minutes=60),
tags=['example', 'example2'],
params={"example_key": "example_value"},
max_active_runs=16,
max_active_tasks=2000,
) as dag:
run_this_last = DummyOperator(
task_id='run_this_last',
)
# [START howto_operator_bash]
run_this = BashOperator(
task_id='run_after_loop',
bash_command='echo "hi"',
)
# [END howto_operator_bash]
run_this >> run_this_last
for i in range(1000):
task = BashOperator(
task_id='runme_' + str(i),
bash_command='echo "{{ task_instance_key_str }}"',
)
task >> run_this
# [START howto_operator_bash_template]
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='sleep 1',
)
# [END howto_operator_bash_template]
also_run_this >> run_this_last
# [START howto_operator_bash_skip]
this_will_skip = BashOperator(
task_id='this_will_skip',
bash_command='echo "1xxxxxxxxxxxxxxxxxxx"',
dag=dag,
)
# [END howto_operator_bash_skip]
this_will_skip >> run_this_last
if __name__ == "__main__":
dag.cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment