adapt celery to honcho setup

This commit is contained in:
Thomas Girod 2025-04-09 14:10:39 +02:00 committed by imperosol
parent a8e529c941
commit e8973d1d1b
7 changed files with 21 additions and 19 deletions

View File

@ -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

View File

@ -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:

View File

@ -1 +1,2 @@
redis: redis-server --port $REDIS_PORT
celery: uv run celery -A sith worker --beat -l INFO

View File

@ -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

View File

@ -100,16 +100,6 @@ cd /mnt/<la_lettre_du_disque>/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)

View File

@ -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)

View File

@ -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"