anmolxlight commented on code in PR #67127:
URL: https://github.com/apache/airflow/pull/67127#discussion_r3475737649
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -389,24 +408,12 @@ def send_workload_to_executor(
Send workload to executor (serialized and executed as a Celery task).
This function is called in ProcessPoolExecutor subprocesses. To avoid
pickling issues with
- team-specific Celery apps, we pass the team_name and reconstruct the
Celery app here.
+ team-specific Celery apps, we pass the team_name and create the app in the
subprocess. The app
+ is cached per subprocess and team so Celery backend resolution is
amortized across publishes.
Review Comment:
Addressed in f4d1080194 — tightened docstring to clarify the cache's durable
win is the scheduler-inline path, not the ProcessPoolExecutor subprocess path.
##########
providers/celery/tests/unit/celery/executors/test_celery_executor.py:
##########
@@ -551,6 +558,100 @@ def
test_send_workload_uses_external_executor_id_as_celery_task_id():
assert result.task_id == pre_assigned_id
[email protected]("team_name", [None, "team-a"])
+def test_get_celery_app_for_workload_reuses_cache_for_same_team(team_name):
+ first_app = mock.Mock()
+ second_app = mock.Mock()
+
+ with mock.patch(
+
"airflow.providers.celery.executors.celery_executor_utils.create_celery_app",
+ side_effect=[first_app, second_app],
+ ) as mock_create_celery_app:
+ assert celery_executor_utils._get_celery_app_for_workload(team_name)
is first_app
+ assert celery_executor_utils._get_celery_app_for_workload(team_name)
is first_app
+
+ mock_create_celery_app.assert_called_once()
+
+
+def test_get_celery_app_for_workload_keeps_cache_team_scoped():
+ team_a_app = mock.Mock()
+ team_b_app = mock.Mock()
+
+ with mock.patch(
+
"airflow.providers.celery.executors.celery_executor_utils.create_celery_app",
+ side_effect=[team_a_app, team_b_app],
+ ) as mock_create_celery_app:
+ assert celery_executor_utils._get_celery_app_for_workload("team-a") is
team_a_app
+ assert celery_executor_utils._get_celery_app_for_workload("team-b") is
team_b_app
+
+ assert mock_create_celery_app.call_count == 2
+
+
+def test_send_workload_reuses_celery_app_for_same_team():
+ """Publishing multiple workloads for the same team reuses the cached
Celery app."""
+ celery_executor_utils._get_celery_app_for_workload.cache_clear()
Review Comment:
Addressed in f4d1080194 — removed the two redundant cache_clear() calls from
the unit tests; the autouse fixture already handles that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]