Airflow 气流2.0中的DAG明细表
如何在Airflow 2.0中计划DAG,使其不在节假日运行 问题1:每月第五个工作日运行一次?Airflow 气流2.0中的DAG明细表,airflow,airflow-scheduler,airflow-operator,Airflow,Airflow Scheduler,Airflow Operator,如何在Airflow 2.0中计划DAG,使其不在节假日运行 问题1:每月第五个工作日运行一次? 问题2:在一个月的第五个工作日运行,如果第五天是假日,那么它应该在非假日的第二天运行?目前不能这样做(至少不是本机运行)。气流DAG接受单个cron表达式或timedelta。如果您不能用其中一个说出所需的调度逻辑,那么您就不能在Airflow中使用此调度。好消息是,Airflow必须解决这个问题,并在未来版本中提供更多的调度功能 也就是说,您可以通过将DAG设置为使用schedule\u inte
问题2:在一个月的第五个工作日运行,如果第五天是假日,那么它应该在非假日的第二天运行?目前不能这样做(至少不是本机运行)。气流DAG接受单个cron表达式或timedelta。如果您不能用其中一个说出所需的调度逻辑,那么您就不能在Airflow中使用此调度。好消息是,Airflow必须解决这个问题,并在未来版本中提供更多的调度功能 也就是说,您可以通过将DAG设置为使用
schedule\u interval=“@daily”
运行,并将BranchPythonOperator
作为DAG的第一个任务来解决此问题。在Python callable中,您可以编写所需的调度逻辑,这意味着如果是每月的第5个工作日,您的函数将返回True,否则将返回False,您的工作流将相应地进行分支。对于True,它将继续执行;对于False,它将结束。这并不理想,但会奏效。可能的模板可以是:
def check_fifth():
#write the logic of finding if today is the 5th working day of the month
if logic:
return "continue_task"
else:
return "stop_task"
with DAG(dag_id='stackoverflow',
default_args=default_args,
schedule_interval="@daily",
catchup=False
) as dag:
start_op = BranchPythonOperator(
task_id='choose',
python_callable=check_fifth
)
stop_op = DummyOperator(
task_id='stop_task'
)
#replace with the operator that you want to actually execute
continue_op = YourOperator(
task_id='continue_task'
)
start_op >> [stop_op, continue_op]