From e8973d1d1bde7f07e647543149ae9b602d189021 Mon Sep 17 00:00:00 2001 From: Thomas Girod Date: Wed, 9 Apr 2025 14:10:39 +0200 Subject: [PATCH] adapt celery to honcho setup --- .env.example | 3 ++- .github/workflows/ci.yml | 1 + Procfile.service | 1 + docs/tutorial/install-advanced.md | 12 +++++++++--- docs/tutorial/install.md | 10 ---------- manage.py | 11 +++++++---- sith/settings.py | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 2d47ad1f..25c259e7 100644 --- a/.env.example +++ b/.env.example @@ -9,7 +9,8 @@ DATABASE_URL=sqlite:///db.sqlite3 #DATABASE_URL=postgres://user:password@127.0.0.1:5432/sith REDIS_PORT=7963 -CACHE_URL=redis://127.0.0.1:${REDIS_PORT}/0 +CACHE_URL=redis://127.0.0.1:7963/0 +BROKER_URL=redis://127.0.0.1:7963/1 # Used to select which other services to run alongside # manage.py, pytest and runserver diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8284d3f..912d5d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ env: SECRET_KEY: notTheRealOne DATABASE_URL: sqlite:///db.sqlite3 CACHE_URL: redis://127.0.0.1:6379/0 + BROKER_URL: redis://127.0.0.1:6379/1 jobs: pre-commit: diff --git a/Procfile.service b/Procfile.service index 4f9c4808..5ff3952b 100644 --- a/Procfile.service +++ b/Procfile.service @@ -1 +1,2 @@ redis: redis-server --port $REDIS_PORT +celery: uv run celery -A sith worker --beat -l INFO diff --git a/docs/tutorial/install-advanced.md b/docs/tutorial/install-advanced.md index fc3f5ab8..367c86dd 100644 --- a/docs/tutorial/install-advanced.md +++ b/docs/tutorial/install-advanced.md @@ -120,7 +120,7 @@ les conflits avec les instances de redis déjà en fonctionnement. ```dotenv REDIS_PORT=6379 -CACHE_URL=redis://127.0.0.1:${REDIS_PORT}/0 +CACHE_URL=redis://127.0.0.1:6379/0 ``` Si on souhaite configurer redis pour communiquer via un socket : @@ -151,7 +151,7 @@ ALTER ROLE sith SET client_encoding TO 'utf8'; ALTER ROLE sith SET default_transaction_isolation TO 'read committed'; ALTER ROLE sith SET timezone TO 'UTC'; -GRANT ALL PRIVILEGES ON DATABASE sith TO SITH; +GRANT ALL PRIVILEGES ON DATABASE sith TO sith; \q ``` @@ -290,9 +290,15 @@ Pour faire tourner Celery, faites la commande suivante dans un terminal à part : ```bash -poetry run celery -A sith worker --beat -l INFO +uv run celery -A sith worker --beat -l INFO ``` +!!!note + + Nous utilisons Redis comme broker pour Celery, + donc vous devez aussi configurer l'URL du broker, + de la même manière que ce qui est décrit plus haut + pour Redis. ## Mettre à jour la base de données antispam diff --git a/docs/tutorial/install.md b/docs/tutorial/install.md index 87e0c33b..c5c5b9d6 100644 --- a/docs/tutorial/install.md +++ b/docs/tutorial/install.md @@ -100,16 +100,6 @@ cd /mnt//vos/fichiers/comme/dhab Python ne fait pas parti des dépendances puisqu'il est automatiquement installé par uv. - -Parmi les dépendances installées se trouve redis (que nous utilisons comme cache). -Redis est un service qui doit être activé pour être utilisé. -Pour cela, effectuez les commandes : - -```bash -sudo systemctl start redis -sudo systemctl enable redis # si vous voulez que redis démarre automatiquement au boot -``` - ## Finaliser l'installation Clonez le projet (depuis votre console WSL, si vous utilisez WSL) diff --git a/manage.py b/manage.py index 101696e2..3d58317e 100755 --- a/manage.py +++ b/manage.py @@ -18,10 +18,10 @@ import logging import os import sys +from django.conf import settings from django.utils.autoreload import DJANGO_AUTORELOAD_ENV from sith.composer import start_composer, stop_composer -from sith.settings import PROCFILE_SERVICE if __name__ == "__main__": logging.basicConfig(encoding="utf-8", level=logging.INFO) @@ -30,8 +30,11 @@ if __name__ == "__main__": from django.core.management import execute_from_command_line - if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and PROCFILE_SERVICE is not None: - start_composer(PROCFILE_SERVICE) - _ = atexit.register(stop_composer, procfile=PROCFILE_SERVICE) + if ( + os.environ.get(DJANGO_AUTORELOAD_ENV) is None + and settings.PROCFILE_SERVICE is not None + ): + start_composer(settings.PROCFILE_SERVICE) + _ = atexit.register(stop_composer, procfile=settings.PROCFILE_SERVICE) execute_from_command_line(sys.argv) diff --git a/sith/settings.py b/sith/settings.py index 05756f05..1539ee41 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -342,7 +342,7 @@ EMAIL_PORT = env.int("EMAIL_PORT", default=25) CELERY_TIMEZONE = TIME_ZONE CELERY_TASK_TRACK_STARTED = True CELERY_TASK_TIME_LIMIT = 30 * 60 -CElERY_BROKER_URL = env.str("CELERY_BROKER_URL", default="redis://localhost:6379/1") +CElERY_BROKER_URL = env.str("BROKER_URL") CELERY_RESULT_BACKEND = "django-db" CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"