在操作员之外使用 Airflow 宏

dre*_*mer 7 macros hadoop airflow

有没有办法在任何运营商之外使用 Airflow 宏?

例如,在 DAG 中,我有一个操作:

datestamp = '{{ ds }}'

print(datestamp) # prints string not the date when I run it for any date

scanner = S3KeySensor(
        task_id='scanner',
        poke_interval=60,
        timeout=24 * 60 * 60,
        soft_fail=False,
        wildcard_match=True,
        bucket_key=getPath() + datestamp, #datestamp correctly replaced with execution date
        bucket_name=bucketName,
        dag=dag)
Run Code Online (Sandbox Code Playgroud)

因此,当调用扫描仪时,“ds”值被替换为预期的执行日期,但我想在其他一些地方使用“ds”值。但在这种情况下,它不会替换值,而是将整个字符串作为“{{ ds }}”。在上面的例子中。打印语句打印“{{ ds }}”而不是执行日期。

Pra*_* R. -5

使用双引号。

datestamp = "{{ ds }}"
print datestamp
Run Code Online (Sandbox Code Playgroud)