48 lines
991 B
Python
48 lines
991 B
Python
import pendulum
|
|
|
|
from airflow.sdk import dag, task
|
|
from airflow.operators.bash import BashOperator
|
|
from textwrap import dedent
|
|
|
|
|
|
@dag(
|
|
schedule=None,
|
|
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
|
catchup=False,
|
|
tags=["demo","stackit-demo"],
|
|
dag_id="stackit_02_regular_operators",
|
|
)
|
|
def regular_operators():
|
|
t1 = BashOperator(
|
|
task_id="print_date",
|
|
bash_command="date",
|
|
)
|
|
|
|
t2 = BashOperator(
|
|
task_id="sleep",
|
|
depends_on_past=False,
|
|
bash_command="sleep 10",
|
|
retries=3,
|
|
)
|
|
|
|
templated_command = dedent(
|
|
"""
|
|
{% for i in range(5) %}
|
|
echo "{{ ds }}"
|
|
echo "{{ macros.ds_add(ds, 7)}}"
|
|
echo "{{ params.my_param }}"
|
|
{% endfor %}
|
|
"""
|
|
)
|
|
|
|
t3 = BashOperator(
|
|
task_id="templated",
|
|
depends_on_past=False,
|
|
bash_command=templated_command,
|
|
params={"my_param": "Parameter I passed in"},
|
|
)
|
|
|
|
t1 >> [t2, t3]
|
|
|
|
|
|
regular_operators()
|