Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to pass extra parameters for celery workers #11

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.12']
python-version: ['3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ CELERY_CMS_EXPLICIT_QUEUES:
queue: edx.cms.core.high
```

### Custom parameters

Each deployment can be configured to run with different paramaters to override the defaults, the setting `extra_param`
is a list that can be used to pass custom parameters to the Celery workers. e.g changing the Celery's pool parameter
for the high_mem lms worker deployment:

```python
@CELERY_WORKERS_CONFIG.add()
def _add_celery_workers_config(workers_config):
# Adding LMS extra queues
workers_config["lms"]["high_mem"]["extra_params"] = {
"--pool=gevent",
"--concurrency=100",
}

return workers_config
```

### Autoscaling

As an alternative to the CPU/memory based autoscaling offered by the plugin [tutor-contrib-pod-autoscaling](https://github.com/eduNEXT/tutor-contrib-pod-autoscaling),
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "tutor-contrib-celery"
dynamic = ["version"]
description = "A Tutor plugin to manage our opinionated Open edX operations"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = { text = "AGPLv3" }
authors = [
{ name = "eduNEXT" }
Expand All @@ -18,14 +18,13 @@ classifiers = [
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"tutor>=18.0.0,<19.0.0"
"tutor>=18.2,<19.0.0"
]

optional-dependencies = { dev = ["python-semantic-release", "pylint", "black"]}
Expand Down
1 change: 1 addition & 0 deletions tutorcelery/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CELERY_WORKERS_ATTRS_TYPE(TypedDict):
max_replicas: NotRequired[int]
list_length: NotRequired[int]
enable_keda: bool
extra_params: NotRequired[list[str]]


CELERY_WORKERS_CONFIG: Filter[dict[str, dict[str, CELERY_WORKERS_ATTRS_TYPE]], []] = (
Expand Down
3 changes: 3 additions & 0 deletions tutorcelery/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ spec:
- "--hostname=edx.{{service}}.core.{{variant}}.%%h"
- "--max-tasks-per-child=100"
- "--queues=edx.{{service}}.core.{{variant}}"
{% for param in config.get("extra_params", []) %}
- "{{param}}"
{% endfor %}
env:
- name: SERVICE_VARIANT
value: {{service}}
Expand Down
26 changes: 0 additions & 26 deletions tutorcelery/patches/k8s-override

This file was deleted.

8 changes: 8 additions & 0 deletions tutorcelery/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def is_celery_multiqueue(service: str) -> bool:
return True


@hooks.Actions.PROJECT_ROOT_READY.add()
def configure_default_workers(root: str) -> None:
if is_celery_multiqueue("lms"):
hooks.Filters.LMS_WORKER_COMMAND.add_items(["--queues=edx.lms.core.default"])
if is_celery_multiqueue("cms"):
hooks.Filters.CMS_WORKER_COMMAND.add_items(["--queues=edx.cms.core.default"])


hooks.Filters.CONFIG_DEFAULTS.add_items(
[
# Add your new settings that have default values here.
Expand Down
Loading