Skip to content

Is possible to add a loop condition in Airflow? #21726

Closed Answered by philippefutureboy
appassionate asked this question in Ideas
Discussion options

You must be logged in to vote

For future references for those that want to implement a looping condition in Airflow, here's a possible implementation:

import abc
from typing import Any, Generic, Mapping, TypeVar, Union
from airflow.utils.operator_helpers import KeywordParameters

T = TypeVar('T')

class AbstractLoop(abc.ABC, Generic[T]):
    """
    Abstract class to execute as a python_callable using a PythonOperator.
    Runs the `run` method until the `condition` method returns false.

    Example:

    PythonOperator(
        task_id="task_looper"
        python_callable=Loop(
            ...args
        ),
        op_kwargs={
            ...op_kwargs
        }
    )
    """

    def __call__(self, **context)
    …

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@appassionate
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@potiuk
Comment options

potiuk Apr 7, 2022
Collaborator

@appassionate
Comment options

@appassionate
Comment options

@potiuk
Comment options

potiuk Apr 7, 2022
Collaborator

@appassionate
Comment options

Comment options

You must be logged in to vote
1 reply
@appassionate
Comment options

Answer selected by appassionate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants