Skip to content

Commit

Permalink
Move default_celery.py to inside the provider (#32628)
Browse files Browse the repository at this point in the history
This has been missed in #32526 and is extracted out from #32604
in an attempt to make it smaller and separately reviewable.

This one adds also deprecation warning to handle the
configuration value that people might already have in
the [celery] iccelery_config_options"
  • Loading branch information
potiuk committed Jul 16, 2023
1 parent c659448 commit ea0deaa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
11 changes: 11 additions & 0 deletions airflow/config_templates/__init__.py
Expand Up @@ -15,3 +15,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from airflow.utils.deprecation_tools import add_deprecated_classes

__deprecated_classes = {
"default_celery": {
"DEFAULT_CELERY_CONFIG": "airflow.providers.celery.executors.default_celery.DEFAULT_CELERY_CONFIG",
},
}

add_deprecated_classes(__deprecated_classes, __name__)
2 changes: 1 addition & 1 deletion airflow/config_templates/config.yml
Expand Up @@ -2145,7 +2145,7 @@ celery:
version_added: ~
type: string
example: ~
default: "airflow.config_templates.default_celery.DEFAULT_CELERY_CONFIG"
default: "airflow.providers.celery.executors.default_celery.DEFAULT_CELERY_CONFIG"
ssl_active:
description: ~
version_added: ~
Expand Down
2 changes: 1 addition & 1 deletion airflow/config_templates/default_airflow.cfg
Expand Up @@ -1109,7 +1109,7 @@ flower_basic_auth =
sync_parallelism = 0

# Import path for celery configuration options
celery_config_options = airflow.config_templates.default_celery.DEFAULT_CELERY_CONFIG
celery_config_options = airflow.providers.celery.executors.default_celery.DEFAULT_CELERY_CONFIG
ssl_active = False

# Path to the client key.
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/celery/executors/celery_executor_utils.py
Expand Up @@ -39,11 +39,11 @@
from setproctitle import setproctitle

import airflow.settings as settings
from airflow.config_templates.default_celery import DEFAULT_CELERY_CONFIG
from airflow.configuration import conf
from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
from airflow.executors.base_executor import BaseExecutor
from airflow.models.taskinstance import TaskInstanceKey
from airflow.providers.celery.executors.default_celery import DEFAULT_CELERY_CONFIG
from airflow.stats import Stats
from airflow.utils.dag_parsing_context import _airflow_parsing_context_manager
from airflow.utils.log.logging_mixin import LoggingMixin
Expand All @@ -64,6 +64,7 @@

if conf.has_option("celery", "celery_config_options"):
celery_configuration = conf.getimport("celery", "celery_config_options")

else:
celery_configuration = DEFAULT_CELERY_CONFIG

Expand Down
Expand Up @@ -74,11 +74,16 @@ def _broker_supports_visibility_timeout(url):
"worker_enable_remote_control": conf.getboolean("celery", "worker_enable_remote_control"),
}

celery_ssl_active = False
try:
celery_ssl_active = conf.getboolean("celery", "SSL_ACTIVE")
except AirflowConfigException:
log.warning("Celery Executor will run without SSL")

def _get_celery_ssl_active() -> bool:
try:
return conf.getboolean("celery", "SSL_ACTIVE")
except AirflowConfigException:
log.warning("Celery Executor will run without SSL")
return False


celery_ssl_active = _get_celery_ssl_active()

try:
if celery_ssl_active:
Expand Down
3 changes: 1 addition & 2 deletions tests/providers/celery/executors/test_celery_executor.py
Expand Up @@ -258,8 +258,7 @@ def test_cleanup_stuck_queued_tasks(self, mock_fail):
def test_result_backend_sqlalchemy_engine_options(self, mock_celery):
import importlib

from airflow.config_templates import default_celery
from airflow.providers.celery.executors import celery_executor_utils
from airflow.providers.celery.executors import celery_executor_utils, default_celery

# reload celery conf to apply the new config
importlib.reload(default_celery)
Expand Down

0 comments on commit ea0deaa

Please sign in to comment.