Files
Barış Keserandgoogle-labs-jules[bot] 5f9fbd0c5a feat(users): Move badge calculation to async Celery tasks (#365)
- 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>
2026-08-01 20:56:30 +00:00

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}')