mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 02:19:59 +03:00
- Created asynchronous tasks `calculate_badges_task`, `calculate_chat_badges_task`, and `reevaluate_all_badges_task` in `users/tasks.py`. - Updated `users/signals.py` to invoke Celery tasks asynchronously via `.delay()` rather than running synchronous functions. - Added `flower` for monitoring in `requirements.txt`. - Configured Celery Result Backend to use Redis instead of `django-db` in `aniscrap_core/settings.py`. - Scheduled `reevaluate_all_badges_task` to run daily via Celery Beat in `aniscrap_core/celery.py`. - Updated `.jules/development-plan.md` to reflect completed Celery optimizations. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
30 lines
897 B
Python
30 lines
897 B
Python
import os
|
|
from celery import Celery
|
|
|
|
# Set the default Django settings module for the 'celery' program.
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aniscrap_core.settings')
|
|
|
|
app = Celery('aniscrap_core')
|
|
|
|
# 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')
|
|
|
|
from celery.schedules import crontab
|
|
|
|
# Load task modules from all registered Django apps.
|
|
app.autodiscover_tasks()
|
|
|
|
app.conf.beat_schedule = {
|
|
'reevaluate_all_badges_daily': {
|
|
'task': 'users.tasks.reevaluate_all_badges_task',
|
|
'schedule': crontab(minute=0, hour=0), # Run daily at midnight
|
|
},
|
|
}
|
|
|
|
@app.task(bind=True)
|
|
def debug_task(self):
|
|
print(f'Request: {self.request!r}')
|