diff --git a/elections/tasks.py b/elections/tasks.py new file mode 100644 index 0000000..fe7a859 --- /dev/null +++ b/elections/tasks.py @@ -0,0 +1,2 @@ +def send_election_mail(election): + pass diff --git a/kadenios/__init__.py b/kadenios/__init__.py index e69de29..53f4ccb 100644 --- a/kadenios/__init__.py +++ b/kadenios/__init__.py @@ -0,0 +1,3 @@ +from .celery import app as celery_app + +__all__ = ("celery_app",) diff --git a/kadenios/celery.py b/kadenios/celery.py new file mode 100644 index 0000000..0cefb00 --- /dev/null +++ b/kadenios/celery.py @@ -0,0 +1,15 @@ +import os + +from celery import Celery + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kadenios.settings.local") + +app = Celery("kadenios") +app.config_from_object("django.conf:settings", namespace="CELERY") + +app.autodiscover_tasks() + + +@app.task(bind=True) +def debug_task(self): + print(f"Request: {self.request!r}") diff --git a/kadenios/settings/common.py b/kadenios/settings/common.py index 6143d80..6c269a0 100644 --- a/kadenios/settings/common.py +++ b/kadenios/settings/common.py @@ -53,6 +53,7 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "kadenios.apps.IgnoreSrcStaticFilesConfig", + "django_celery_results", "shared", "elections", "faqs", @@ -94,6 +95,13 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField" DEFAULT_FROM_EMAIL = "Kadenios " +# ############################################################################# +# Paramètres de Celery +# ############################################################################# + +CELERY_RESULT_BACKEND = "django-db" +CELERY_CACHE_BACKEND = "default" + # ############################################################################# # Paramètres d'authentification # ############################################################################# diff --git a/requirements.txt b/requirements.txt index bc3ab09..40021df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ django==3.2.* +celery==5.1.* +django-celery-results django-translated-fields==0.11.1 authens>=0.1b2 markdown