added celery

This commit is contained in:
Alexander Karpov 2022-07-30 03:25:43 +03:00
parent ee52b67eea
commit c8e3b049f5
5 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ("celery_app",)

21
chess_backend/celery.py Normal file
View File

@ -0,0 +1,21 @@
import os
from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chess_backend.settings")
app = Celery("chess_backend")
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True, ignore_result=True)
def debug_task(self):
print(f"Request: {self.request!r}")

View File

@ -124,3 +124,9 @@ LOGGING = {
},
},
}
# Celery Configuration Options
CELERY_TIMEZONE = "Europe/Moscow"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
CELERY_BROKER_URL = 'redis://localhost:6379/0'

View File

@ -4,3 +4,5 @@ djangorestframework==3.13.1
Pillow==9.1.1
PyJWT==2.4.0
channels-redis==3.4.1
celery==5.2.7
redis==4.3.4

3
room/tasks.py Normal file
View File

@ -0,0 +1,3 @@
from celery import shared_task
# TODO: add timeout for state