Skip to content

Commit

Permalink
feat: add two filters to customise celery workers command
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 authored Nov 22, 2024
1 parent 8c7996c commit e6bbd25
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/20241119_100430_crisgarta8_celery_queues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 💥 [Feature] Add a filter to define the celery workers startup command. (by @Ian2012)
10 changes: 10 additions & 0 deletions tutor/hooks/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,16 @@ def your_filter_callback(some_data):
#: :param str file_path: The path to the file being checked.
IS_FILE_RENDERED: Filter[bool, [str]] = Filter()

#: List of parameters to use when starting the LMS Celery worker ``celery worker ...``.
#:
#: :param list[str] command: the list of paramaters to use as the celery command.
LMS_WORKER_COMMAND: Filter[list[str], []] = Filter()

#: List of parameters to use when starting the CMS Celery worker ``celery worker ...``.
#:
#: :param list[str] command: the list of paramaters to use as the celery command.
CMS_WORKER_COMMAND: Filter[list[str], []] = Filter()


class Contexts:
"""
Expand Down
42 changes: 42 additions & 0 deletions tutor/plugins/openedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,45 @@ def is_directory_mounted(image_name: str, dirname: str) -> bool:
hooks.Filters.ENV_TEMPLATE_VARIABLES.add_item(
("iter_mounted_directories", iter_mounted_directories)
)


hooks.Filters.LMS_WORKER_COMMAND.add_items(
[
"celery",
"--app=lms.celery",
"worker",
"--loglevel=info",
"--hostname=edx.lms.core.default.%h",
"--queues=edx.lms.core.default,edx.lms.core.high,edx.lms.core.high_mem",
"--max-tasks-per-child=100",
]
)


hooks.Filters.CMS_WORKER_COMMAND.add_items(
[
"celery",
"--app=cms.celery",
"worker",
"--loglevel=info",
"--hostname=edx.cms.core.default.%h",
"--queues=edx.cms.core.default,edx.cms.core.high,edx.cms.core.low",
"--max-tasks-per-child=100",
]
)


def iter_cms_celery_parameters() -> t.Iterator[str]:
yield from hooks.Filters.CMS_WORKER_COMMAND.iterate()


def iter_lms_celery_parameters() -> t.Iterator[str]:
yield from hooks.Filters.LMS_WORKER_COMMAND.iterate()


hooks.Filters.ENV_TEMPLATE_VARIABLES.add_items(
[
("iter_cms_celery_parameters", iter_cms_celery_parameters),
("iter_lms_celery_parameters", iter_lms_celery_parameters),
]
)
7 changes: 5 additions & 2 deletions tutor/templates/k8s/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ spec:
containers:
- name: cms-worker
image: {{ DOCKER_IMAGE_OPENEDX }}
args: ["celery", "--app=cms.celery", "worker", "--loglevel=info", "--hostname=edx.cms.core.default.%%h", "--max-tasks-per-child", "100", "--exclude-queues=edx.lms.core.default"]
args:
{% for value in iter_cms_celery_parameters() %}
- "{{value}}"{% endfor %}
env:
- name: SERVICE_VARIANT
value: cms
Expand Down Expand Up @@ -250,7 +252,8 @@ spec:
containers:
- name: lms-worker
image: {{ DOCKER_IMAGE_OPENEDX }}
args: ["celery", "--app=lms.celery", "worker", "--loglevel=info", "--hostname=edx.lms.core.default.%%h", "--max-tasks-per-child=100", "--exclude-queues=edx.cms.core.default"]
args: {% for value in iter_lms_celery_parameters() %}
- "{{value}}"{% endfor %}
env:
- name: SERVICE_VARIANT
value: lms
Expand Down
6 changes: 4 additions & 2 deletions tutor/templates/local/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ services:
environment:
SERVICE_VARIANT: lms
DJANGO_SETTINGS_MODULE: lms.envs.tutor.production
command: celery --app=lms.celery worker --loglevel=info --hostname=edx.lms.core.default.%%h --max-tasks-per-child=100 --exclude-queues=edx.cms.core.default
command: {% for value in iter_lms_celery_parameters() %}
- "{{value}}"{% endfor %}
restart: unless-stopped
volumes:
- ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro
Expand All @@ -50,7 +51,8 @@ services:
environment:
SERVICE_VARIANT: cms
DJANGO_SETTINGS_MODULE: cms.envs.tutor.production
command: celery --app=cms.celery worker --loglevel=info --hostname=edx.cms.core.default.%%h --max-tasks-per-child 100 --exclude-queues=edx.lms.core.default
command: {% for value in iter_lms_celery_parameters() %}
- "{{value}}"{% endfor %}
restart: unless-stopped
volumes:
- ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro
Expand Down

0 comments on commit e6bbd25

Please sign in to comment.