Python ile Apache Airflow'a Giriş
Mike Metzger
Data Engineer
templated_command="""
echo "Reading {{ params.filename }}"
"""
t1 = BashOperator(task_id='template_task',
bash_command=templated_command,
params={'filename': 'file1.txt'},
dag=example_dag)
templated_command=""" {% for filename in params.filenames %}echo "Reading {{ filename }}"{% endfor %} """t1 = BashOperator(task_id='template_task', bash_command=templated_command, params={'filenames': ['file1.txt', 'file2.txt']}, dag=example_dag)
Reading file1.txt
Reading file2.txt
Execution Date: {{ ds }} # YYYY-MM-DD Execution Date, no dashes: {{ ds_nodash }} # YYYYMMDDPrevious Execution date: {{ prev_ds }} # YYYY-MM-DD Prev Execution date, no dashes: {{ prev_ds_nodash }} # YYYYMMDDDAG object: {{ dag }}Airflow config object: {{ conf }}
Diğerlerine ek olarak, bir de {{ macros }} değişkeni vardır.
Bu, Airflow şablonları için çeşitli yararlı nesne/yöntemler sağlayan Airflow macros paketine bir referanstır.
{{ macros.datetime }}: datetime.datetime nesnesi{{ macros.timedelta }}: timedelta nesnesi{{ macros.uuid }}: Python'un uuid nesnesi{{ macros.ds_add('2020-04-15', 5) }}: Bir tarihe gün ekler; bu örnek 2020-04-20 döndürürPython ile Apache Airflow'a Giriş