Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions airflow/providers/celery/executors/celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import time
from collections import Counter
from concurrent.futures import ProcessPoolExecutor
from importlib.metadata import version as importlib_version
from multiprocessing import cpu_count
from typing import TYPE_CHECKING, Any, Optional, Sequence, Tuple

from celery import states as celery_states
from packaging.version import Version

try:
from airflow.cli.cli_config import (
Expand Down Expand Up @@ -178,11 +180,19 @@ def __getattr__(name):
action="store_true",
)

AIRFLOW_VERSION = Version(importlib_version("apache-airflow"))

CELERY_CLI_COMMAND_PATH = (
"airflow.providers.celery.cli.celery_command"
if AIRFLOW_VERSION >= Version("2.8.0")
else "airflow.cli.commands.celery_command"
)

CELERY_COMMANDS = (
ActionCommand(
name="worker",
help="Start a Celery worker node",
func=lazy_load_command("airflow.providers.celery.cli.celery_command.worker"),
func=lazy_load_command(f"{CELERY_CLI_COMMAND_PATH}.worker"),
args=(
ARG_QUEUES,
ARG_CONCURRENCY,
Expand All @@ -203,7 +213,7 @@ def __getattr__(name):
ActionCommand(
name="flower",
help="Start a Celery Flower",
func=lazy_load_command("airflow.providers.celery.cli.celery_command.flower"),
func=lazy_load_command(f"{CELERY_CLI_COMMAND_PATH}.flower"),
args=(
ARG_FLOWER_HOSTNAME,
ARG_FLOWER_PORT,
Expand All @@ -222,7 +232,7 @@ def __getattr__(name):
ActionCommand(
name="stop",
help="Stop the Celery worker gracefully",
func=lazy_load_command("airflow.providers.celery.cli.celery_command.stop_worker"),
func=lazy_load_command(f"{CELERY_CLI_COMMAND_PATH}.stop_worker"),
args=(ARG_PID, ARG_VERBOSE),
),
)
Expand Down