Apache Airflow Celery Provider

3.17.2 · active · verified Sat Apr 11

This provider package integrates Apache Airflow with Celery, enabling the use of Celery workers for task execution. It allows Airflow to scale task processing by distributing tasks to a pool of Celery workers, using message brokers like RabbitMQ or Redis. The current version is 3.17.2, and releases are tied to the Apache Airflow release cycle, typically monthly or bi-monthly.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Airflow DAG that uses Celery-specific task queuing. For this to work, you must configure your `airflow.cfg` to use `executor = CeleryExecutor` and start Celery workers configured to listen to the specified queues (e.g., `airflow celery worker -q high_priority,default`).

import pendulum

from airflow.models.dag import DAG
from airflow.operators.bash import BashOperator

with DAG(
    dag_id="celery_executor_example",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=["celery", "example"],
) as dag:
    # This task will run on a worker designated for the 'high_priority' queue
    high_priority_task = BashOperator(
        task_id="run_on_high_priority_queue",
        bash_command="echo 'Running on high priority queue' && sleep 5",
        queue="high_priority", # Configure Celery worker to listen to this queue
    )

    # This task will run on a worker designated for the 'default' queue
    default_queue_task = BashOperator(
        task_id="run_on_default_queue",
        bash_command="echo 'Running on default queue' && sleep 2",
        queue="default", # Or omit, if default queue is configured
    )

    high_priority_task >> default_queue_task

view raw JSON →