Skip to content

Instantly share code, notes, and snippets.

@cra
Last active December 7, 2023 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cra/681a3590d1bc74fa299e66b548b17dbb to your computer and use it in GitHub Desktop.
Save cra/681a3590d1bc74fa299e66b548b17dbb to your computer and use it in GitHub Desktop.
from pendulum import datetime
from airflow.decorators import dag, task, task_group
from airflow.operators.empty import EmptyOperator
@dag(
tags=["test"],
schedule=None,
start_date=datetime(2023, 8, 1),
catchup=False,
)
def IdillaylaI_branching():
start = EmptyOperator(task_id='start')
end = EmptyOperator(task_id='end')
@task_group
def gr1():
pre = EmptyOperator(task_id='prewere')
calcul1 = EmptyOperator(task_id='calculate1', trigger_rule='one_success')
@task
def calculate2():
return "crunching numbers like there's no tomorrow"
@task
def checking():
return 1
@task.branch
def branch(result):
if not result:
return 'gr1.prewere'
else:
return 'gr1.calculate1'
branch(checking()) >> [pre, calcul1]
pre >> calcul1 >> calculate2()
start >> gr1() >> end
IdillaylaI_branching()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment