mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-17 03:20:20 +00:00
adapt celery to honcho setup
This commit is contained in:
parent
278b875f86
commit
5d1ba76229
@ -9,7 +9,8 @@ DATABASE_URL=sqlite:///db.sqlite3
|
|||||||
#DATABASE_URL=postgres://user:password@127.0.0.1:5432/sith
|
#DATABASE_URL=postgres://user:password@127.0.0.1:5432/sith
|
||||||
|
|
||||||
REDIS_PORT=7963
|
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
|
# Used to select which other services to run alongside
|
||||||
# manage.py, pytest and runserver
|
# manage.py, pytest and runserver
|
||||||
|
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -11,6 +11,7 @@ env:
|
|||||||
SECRET_KEY: notTheRealOne
|
SECRET_KEY: notTheRealOne
|
||||||
DATABASE_URL: sqlite:///db.sqlite3
|
DATABASE_URL: sqlite:///db.sqlite3
|
||||||
CACHE_URL: redis://127.0.0.1:6379/0
|
CACHE_URL: redis://127.0.0.1:6379/0
|
||||||
|
BROKER_URL: redis://127.0.0.1:6379/1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
|
@ -1 +1,2 @@
|
|||||||
redis: redis-server --port $REDIS_PORT
|
redis: redis-server --port $REDIS_PORT
|
||||||
|
celery: uv run celery -A sith worker --beat -l INFO
|
||||||
|
@ -66,7 +66,6 @@ from core.views.forms import (
|
|||||||
)
|
)
|
||||||
from core.views.mixins import QuickNotifMixin, TabedViewMixin, UseFragmentsMixin
|
from core.views.mixins import QuickNotifMixin, TabedViewMixin, UseFragmentsMixin
|
||||||
from counter.models import Counter, Refilling, Selling
|
from counter.models import Counter, Refilling, Selling
|
||||||
from counter.views.student_card import StudentCardFormFragment
|
|
||||||
from eboutic.models import Invoice
|
from eboutic.models import Invoice
|
||||||
from subscription.models import Subscription
|
from subscription.models import Subscription
|
||||||
from trombi.views import UserTrombiForm
|
from trombi.views import UserTrombiForm
|
||||||
@ -529,6 +528,8 @@ class UserPreferencesView(UserTabsMixin, UseFragmentsMixin, CanEditMixin, Update
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_fragment_context_data(self) -> dict[str, SafeString]:
|
def get_fragment_context_data(self) -> dict[str, SafeString]:
|
||||||
|
from counter.views.student_card import StudentCardFormFragment
|
||||||
|
|
||||||
res = super().get_fragment_context_data()
|
res = super().get_fragment_context_data()
|
||||||
if hasattr(self.object, "customer"):
|
if hasattr(self.object, "customer"):
|
||||||
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
|
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
|
||||||
|
@ -120,7 +120,7 @@ les conflits avec les instances de redis déjà en fonctionnement.
|
|||||||
|
|
||||||
```dotenv
|
```dotenv
|
||||||
REDIS_PORT=6379
|
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 :
|
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 default_transaction_isolation TO 'read committed';
|
||||||
ALTER ROLE sith SET timezone TO 'UTC';
|
ALTER ROLE sith SET timezone TO 'UTC';
|
||||||
|
|
||||||
GRANT ALL PRIVILEGES ON DATABASE sith TO SITH;
|
GRANT ALL PRIVILEGES ON DATABASE sith TO sith;
|
||||||
\q
|
\q
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -290,9 +290,15 @@ Pour faire tourner Celery, faites la commande suivante dans
|
|||||||
un terminal à part :
|
un terminal à part :
|
||||||
|
|
||||||
```bash
|
```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
|
## Mettre à jour la base de données antispam
|
||||||
|
|
||||||
|
@ -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
|
Python ne fait pas parti des dépendances puisqu'il est automatiquement
|
||||||
installé par uv.
|
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
|
## Finaliser l'installation
|
||||||
|
|
||||||
Clonez le projet (depuis votre console WSL, si vous utilisez WSL)
|
Clonez le projet (depuis votre console WSL, si vous utilisez WSL)
|
||||||
|
11
manage.py
11
manage.py
@ -18,10 +18,10 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
||||||
|
|
||||||
from sith.composer import start_composer, stop_composer
|
from sith.composer import start_composer, stop_composer
|
||||||
from sith.settings import PROCFILE_SERVICE
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(encoding="utf-8", level=logging.INFO)
|
logging.basicConfig(encoding="utf-8", level=logging.INFO)
|
||||||
@ -30,8 +30,11 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and PROCFILE_SERVICE is not None:
|
if (
|
||||||
start_composer(PROCFILE_SERVICE)
|
os.environ.get(DJANGO_AUTORELOAD_ENV) is None
|
||||||
_ = atexit.register(stop_composer, procfile=PROCFILE_SERVICE)
|
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)
|
execute_from_command_line(sys.argv)
|
||||||
|
@ -343,7 +343,7 @@ EMAIL_PORT = env.int("EMAIL_PORT", default=25)
|
|||||||
CELERY_TIMEZONE = TIME_ZONE
|
CELERY_TIMEZONE = TIME_ZONE
|
||||||
CELERY_TASK_TRACK_STARTED = True
|
CELERY_TASK_TRACK_STARTED = True
|
||||||
CELERY_TASK_TIME_LIMIT = 30 * 60
|
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_RESULT_BACKEND = "django-db"
|
||||||
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
|
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user