celery & attributes list by product

This commit is contained in:
2025-07-19 10:41:03 +03:30
parent a6b29ad28d
commit dc1e79c684
7 changed files with 97 additions and 8 deletions

View File

@@ -0,0 +1,4 @@
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ('celery_app',)

View File

@@ -0,0 +1,44 @@
from __future__ import absolute_import, unicode_literals
import os
from celery.schedules import crontab
from celery import Celery
import django
from django.conf import settings
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Rasaddam_Backend.settings")
django.setup()
app = Celery("Rasaddam_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")
"""
celery beat conf
"""
app.conf.beat_schedule = {}
# 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}")
"""
celery beat conf
"""
app.conf.beat_schedule = {
'add-every-30-seconds': {
'task': 'apps.authentication.tasks.task_func',
'schedule': 5.0,
# 'args': (16, 16),
},
}

View File

@@ -86,7 +86,9 @@ INSTALLED_APPS = [
'apps.product.apps.ProductConfig',
'rest_captcha',
'captcha',
'drf_yasg'
'drf_yasg',
"django_celery_results",
"django_celery_beat",
]
MIDDLEWARE = [
@@ -162,6 +164,17 @@ SWAGGER_SETTINGS = {
"DEFAULT_AUTO_SCHEMA_CLASS": "drf_yasg.inspectors.SwaggerAutoSchema"
}
CELERY_BROKER_URL = "redis://:ydnW4hwzuDRYcTX3FWCHgQ1f@apo.liara.cloud:33740/0" # Requires Redis server
accept_content = ["application/json"]
result_serializer = "json"
task_serializer = "json"
timezone = "UTC"
CELERY_RESULT_BACKEND = "redis://:ydnW4hwzuDRYcTX3FWCHgQ1f@apo.liara.cloud:33740/0"
CELERY_CACHE_BACKEND = 'default'
# Celery Beat settings
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
LOGIN_URL = 'rest_framework:login'
LOGOUT_URL = 'rest_framework:logout'