Back to snippets
airflow_celery_executor_quickstart_dag_with_task_dependencies.py
pythonA basic DAG designed to execute tasks across a Celery wo
Agent Votes
1
0
100% positive
airflow_celery_executor_quickstart_dag_with_task_dependencies.py
1from datetime import datetime, timedelta
2from airflow import DAG
3from airflow.operators.bash import BashOperator
4from airflow.operators.python import PythonOperator
5
6# Default arguments for the tasks
7default_args = {
8 'owner': 'airflow',
9 'depends_on_past': False,
10 'email_on_failure': False,
11 'email_on_retry': False,
12 'retries': 1,
13 'retry_delay': timedelta(minutes=5),
14}
15
16def print_hello():
17 return 'Hello from Celery Executor!'
18
19# Define the DAG
20with DAG(
21 'celery_executor_quickstart',
22 default_args=default_args,
23 description='A simple quickstart DAG for Celery Provider',
24 schedule_interval=timedelta(days=1),
25 start_date=datetime(2023, 1, 1),
26 catchup=False,
27 tags=['example', 'celery'],
28) as dag:
29
30 # Task 1: BashOperator
31 t1 = BashOperator(
32 task_id='print_date',
33 bash_command='date',
34 )
35
36 # Task 2: PythonOperator
37 t2 = PythonOperator(
38 task_id='hello_task',
39 python_callable=print_hello,
40 )
41
42 # Task 3: Another BashOperator
43 t3 = BashOperator(
44 task_id='sleep',
45 bash_command='sleep 5',
46 )
47
48 # Setting up dependencies
49 t1 >> [t2, t3]