问题
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