Skip to content

Commit

Permalink
feat: allow to pass extra parameters for celery workers
Browse files Browse the repository at this point in the history
(cherry picked from commit c858d5d)

docs: add section with extra parameters

docs: add section with extra parameters

refactor!: use new filter to define celery command

(cherry picked from commit 53fafef)
  • Loading branch information
Ian2012 committed Dec 12, 2024
1 parent dbf81e1 commit c176c05
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
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 configuration `extra_param`
is a dictionary that can be used to pass custom parameters to the Celery workers. e.g changing the Celery's pool parameter
for the default 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

0 comments on commit c176c05

Please sign in to comment.