Airflow skip current task

你离开我真会死。 提交于 2020-01-24 12:15:06

问题


Is there a way for Airflow to skip current task from within the (Python)Operator? For example:

def execute():
    if condition:
        skip_current_task()

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)

Skipping downstream tasks doesn't suit me (a solution proposed in this answer: How to skip tasks on Airflow?), as well as branching. Is there a way for a task to mark its state as skipped from within the Operator?


回答1:


Figured it out! Skipping task is as easy as:

def execute():
    if condition:
        raise AirflowSkipException

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)



回答2:


The easiest solution to skip a task:

def execute():
    if condition:
        return

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)

Unfortunately, it will mark task as DONE



来源:https://stackoverflow.com/questions/58414350/airflow-skip-current-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!