Modified settings and added celery

This commit is contained in:
Viswamedha Nalabotu 2025-12-10 13:44:56 +00:00
parent 683f6c1b98
commit b1ecd01507
5 changed files with 60 additions and 8 deletions

View file

@ -0,0 +1,3 @@
from .celery import app as celery_app
__all__ = ('celery_app',)

8
config/celery.py Normal file
View file

@ -0,0 +1,8 @@
from celery import Celery
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
app = Celery('config')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

View file

@ -35,6 +35,9 @@ DJANGO_APPS = [
THIRD_PARTY_APPS = [
'rest_framework',
'channels',
'django_celery_results',
'django_celery_beat',
'corsheaders',
]
LOCAL_APPS = [
'apps.users',
@ -49,6 +52,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@ -63,8 +67,11 @@ ASGI_APPLICATION = f'{PARENT_NAME}.asgi.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer'
}
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [os.getenv('CELERY_BROKER_URL')],
},
},
}
TEMPLATES = [
@ -83,13 +90,32 @@ TEMPLATES = [
]
DB_ENGINE = os.getenv('DJANGO_DB_ENGINE', 'django.db.backends.sqlite3')
DB_NAME = os.getenv('DJANGO_DB_NAME', BASE_DIR / 'db.sqlite3')
DB_USER = os.getenv('DJANGO_DB_USER')
DB_PASSWORD = os.getenv('DJANGO_DB_PASSWORD')
DB_HOST = os.getenv('DJANGO_DB_HOST')
DB_PORT = os.getenv('DJANGO_DB_PORT', 5432)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': DB_ENGINE,
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': DB_PORT,
'CONN_MAX_AGE': 600,
}
}
if DB_ENGINE == 'django.db.backends.sqlite3':
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': DB_NAME,
}
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
@ -116,7 +142,6 @@ TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
@ -126,3 +151,19 @@ REST_FRAMEWORK = {
'rest_framework.permissions.AllowAny',
],
}
CELERY_BROKER_URL = os.getenv('DJANGO_CELERY_BROKER_URL')
CELERY_RESULT_BACKEND = 'django-db'
CELERY_CACHE_BACKEND = 'django-cache'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
CORS_ALLOWED_ORIGINS = os.getenv('DJANGO_CORS_ALLOWED_ORIGINS').split(',') if os.getenv('DJANGO_CORS_ALLOWED_ORIGINS') else []
CORS_ALLOW_CREDENTIALS = True
if DEBUG:
SECURE_CROSS_ORIGIN_OPENER_POLICY = None