From a1d086882c3df4b057061ba2acaf5c15a9e03c5e Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 17 Mar 2026 16:17:15 +0800 Subject: [PATCH] perf: update celery service run --- apps/common/management/commands/services/command.py | 13 +++++-------- .../commands/services/services/__init__.py | 1 + .../commands/services/services/celery_combine.py | 11 +++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 apps/common/management/commands/services/services/celery_combine.py diff --git a/apps/common/management/commands/services/command.py b/apps/common/management/commands/services/command.py index d5b31d37f..27ce96846 100644 --- a/apps/common/management/commands/services/command.py +++ b/apps/common/management/commands/services/command.py @@ -23,6 +23,7 @@ class Services(TextChoices): gunicorn = 'gunicorn', 'gunicorn' celery_ansible = 'celery_ansible', 'celery_ansible' celery_default = 'celery_default', 'celery_default' + celery_combine = 'celery_combine', 'celery_combine' beat = 'beat', 'beat' flower = 'flower', 'flower' ws = 'ws', 'ws' @@ -39,21 +40,22 @@ class Services(TextChoices): cls.flower: services.FlowerService, cls.celery_default: services.CeleryDefaultService, cls.celery_ansible: services.CeleryAnsibleService, + cls.celery_combine: services.CeleryCombineService, cls.beat: services.BeatService, } return services_map.get(name) @classmethod def web_services(cls): - if SERVER_SIZE == 'small' or os.environ.get('FLOWER_DIABLED', '0') == '1': + if SERVER_SIZE == 'small' or os.environ.get('FLOWER_ENABLED', '1') == '0': return [cls.gunicorn] else: return [cls.gunicorn, cls.flower] @classmethod def celery_services(cls): - if SERVER_SIZE == 'small' or os.environ.get('CELERY_COMBINE', '0') == '1': - return [cls.celery_default] + if SERVER_SIZE == 'small' or os.environ.get('CELERY_COMBINE_QUEUES', '0') == '1': + return [cls.celery_combine] else: return [cls.celery_ansible, cls.celery_default] @@ -122,18 +124,13 @@ class BaseActionCommand(BaseCommand): def get_services_kwargs(self, options): worker = options.get('worker', 4) - default_queue = 'celery' if SERVER_SIZE == 'small': worker = 1 - default_queue = 'celery,ansible' return { 'gunicorn': { 'worker': worker - }, - 'celery_default': { - 'queue': default_queue } } diff --git a/apps/common/management/commands/services/services/__init__.py b/apps/common/management/commands/services/services/__init__.py index 35329a7d4..430e9891e 100644 --- a/apps/common/management/commands/services/services/__init__.py +++ b/apps/common/management/commands/services/services/__init__.py @@ -1,5 +1,6 @@ from .beat import * from .celery_ansible import * from .celery_default import * +from .celery_combine import * from .flower import * from .gunicorn import * diff --git a/apps/common/management/commands/services/services/celery_combine.py b/apps/common/management/commands/services/services/celery_combine.py new file mode 100644 index 000000000..a5b766bf4 --- /dev/null +++ b/apps/common/management/commands/services/services/celery_combine.py @@ -0,0 +1,11 @@ +from .celery_base import CeleryBaseService + +__all__ = ['CeleryCombineService'] + + +class CeleryCombineService(CeleryBaseService): + + def __init__(self, **kwargs): + kwargs['queue'] = 'ansible,celery' + super().__init__(**kwargs) +