zeyger
zeyger

Reputation: 1390

How to skip task in Airflow operator?

Is there a way for Airflow to skip current task from the PythonOperator? For example:

def execute():
    if condition:
        skip_current_task()

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

And also marking the task as "Skipped" in Airflow UI?

Upvotes: 11

Views: 13008

Answers (2)

zeyger
zeyger

Reputation: 1390

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)

Upvotes: 28

Artem Vovsia
Artem Vovsia

Reputation: 1570

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

Upvotes: 0

Related Questions