Skip to content

Instantly share code, notes, and snippets.

@goodbyegangster
Last active June 26, 2022 02:15
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 goodbyegangster/033bcf13d707f05ae81028867d71eb24 to your computer and use it in GitHub Desktop.
Save goodbyegangster/033bcf13d707f05ae81028867d71eb24 to your computer and use it in GitHub Desktop.
Apache Airflow Sample ShortCircuitOperator DAG
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import ShortCircuitOperator
from airflow.operators.empty import EmptyOperator
def is_even_number() -> bool:
import random
number = random.randint(1, 10)
print(number)
if number % 2 == 0:
return True
else:
return False
with DAG(
dag_id='sample_sco',
description='A Sample ShortCircuitOperator DAG',
schedule_interval=timedelta(days=1),
start_date=datetime(2022, 6, 1),
catchup=False,
tags=['sample'],
) as dag:
# airflow.operators.python.ShortCircuitOperator
# https://github.com/apache/airflow/blob/main/airflow/operators/python.py
short_circuit_operator = ShortCircuitOperator(
task_id='short_circuit_operator',
python_callable=is_even_number
)
# airflow.operators.empty
# https://github.com/apache/airflow/blob/main/airflow/operators/empty.py
execute_only_even_number = EmptyOperator(task_id='execute_only_even_number') # noqa: E501
# setting up dependencies.
short_circuit_operator >> execute_only_even_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment