首页 > 解决方案 > Airflow BashOperator 针对特定路径

问题描述

在气流任务中,我想使用 BashOperator 来调用CURL以下载 .csv。我想将其保存在特定位置。这是一个明智的使用模式还是有更好的方法(可能使用模板?):

from pathlib import Path
base_path = Path('/home/dan.golding/projects/subproject/results')

然后在DAG with声明中:

t1 = BashOperator(
        task_id='task_1',
        bash_command=f"curl -X GET 'https://myurl.com/api.php?paramname=paramvalue' > {base_path / 'my_result.csv'}"
        retries=2,
        retry_delay=timedelta(minutes=1))

标签: pythonbashcurlairflowstring-interpolation

解决方案


推荐阅读