139 lines
4.8 KiB
Python
139 lines
4.8 KiB
Python
"""
|
|
Celery configuration for PX360 project.
|
|
"""
|
|
import os
|
|
|
|
from celery import Celery
|
|
from celery.schedules import crontab
|
|
|
|
# Set the default Django settings module for the 'celery' program.
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')
|
|
|
|
app = Celery('px360')
|
|
|
|
# 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()
|
|
|
|
# Celery Beat schedule for periodic tasks
|
|
app.conf.beat_schedule = {
|
|
# Process unprocessed integration events every 1 minute
|
|
'process-integration-events': {
|
|
'task': 'apps.integrations.tasks.process_pending_events',
|
|
'schedule': crontab(minute='*/1'),
|
|
},
|
|
# Check for overdue complaints every 15 minutes
|
|
'check-overdue-complaints': {
|
|
'task': 'apps.complaints.tasks.check_overdue_complaints',
|
|
'schedule': crontab(minute='*/15'),
|
|
},
|
|
# Check for overdue actions every 15 minutes
|
|
'check-overdue-actions': {
|
|
'task': 'apps.px_action_center.tasks.check_overdue_actions',
|
|
'schedule': crontab(minute='*/15'),
|
|
},
|
|
# Send SLA reminders every hour
|
|
'send-sla-reminders': {
|
|
'task': 'apps.complaints.tasks.send_sla_reminders',
|
|
'schedule': crontab(minute=0), # Every hour at minute 0
|
|
},
|
|
# Check for overdue explanation requests every 15 minutes
|
|
'check-overdue-explanation-requests': {
|
|
'task': 'apps.complaints.tasks.check_overdue_explanation_requests',
|
|
'schedule': crontab(minute='*/15'),
|
|
},
|
|
# Send explanation reminders every hour
|
|
'send-explanation-reminders': {
|
|
'task': 'apps.complaints.tasks.send_explanation_reminders',
|
|
'schedule': crontab(minute=0), # Every hour at minute 0
|
|
},
|
|
# Send onboarding reminders every hour
|
|
'send-onboarding-reminders': {
|
|
'task': 'apps.accounts.tasks.send_onboarding_reminders',
|
|
'schedule': crontab(minute=30), # Every hour at minute 30
|
|
},
|
|
# Clean up expired invitations daily at midnight
|
|
'cleanup-expired-invitations': {
|
|
'task': 'apps.accounts.tasks.cleanup_expired_invitations',
|
|
'schedule': crontab(hour=0, minute=0), # Daily at midnight
|
|
},
|
|
# Calculate daily KPIs at 1 AM
|
|
'calculate-daily-kpis': {
|
|
'task': 'apps.analytics.tasks.calculate_daily_kpis',
|
|
'schedule': crontab(hour=1, minute=0),
|
|
},
|
|
# Calculate physician monthly ratings on the 1st of each month at 2 AM
|
|
'calculate-physician-ratings': {
|
|
'task': 'apps.physicians.tasks.calculate_monthly_ratings',
|
|
'schedule': crontab(hour=2, minute=0, day_of_month=1),
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
# ==========================================
|
|
# Social Media Platform Sync Tasks
|
|
# ==========================================
|
|
|
|
# LinkedIn - Sync comments every 30 minutes
|
|
'sync-linkedin-comments-every-30-mins': {
|
|
'task': 'apps.social.tasks.linkedin.sync_all_accounts_task',
|
|
'schedule': 1800.0, # 30 minutes in seconds
|
|
},
|
|
|
|
# Google Reviews - Sync daily at midnight
|
|
'sync-google-reviews-daily': {
|
|
'task': 'apps.social.tasks.google.sync_all_accounts_periodic',
|
|
'schedule': crontab(hour=0, minute=0),
|
|
},
|
|
|
|
# Meta (Facebook/Instagram) - Poll new comments every 30 minutes
|
|
'sync-meta-comments-every-30-mins': {
|
|
'task': 'apps.social.tasks.meta.meta_poll_new_comments_task',
|
|
'schedule': 1800.0, # 30 minutes in seconds
|
|
},
|
|
|
|
# TikTok - Poll new comments every 30 minutes
|
|
'sync-tiktok-comments-every-30-mins': {
|
|
'task': 'apps.social.tasks.tiktok.poll_new_comments_task',
|
|
'schedule': 1800.0, # 30 minutes in seconds
|
|
},
|
|
|
|
# X (Twitter) - Sync all accounts every 30 minutes
|
|
'sync-x-comments-every-30-mins': {
|
|
'task': 'apps.social.tasks.x.sync_all_accounts_periodic',
|
|
'schedule': 1800.0, # 30 minutes in seconds
|
|
},
|
|
|
|
# YouTube - Poll new comments every 30 minutes
|
|
'sync-youtube-comments-every-30-mins': {
|
|
'task': 'apps.social.tasks.youtube.poll_new_comments_task',
|
|
'schedule': 1800.0, # 30 minutes in seconds
|
|
},
|
|
|
|
# ==========================================
|
|
# AI Analysis Tasks
|
|
# ==========================================
|
|
|
|
# AI Analysis - Daily check for unanalyzed comments at 2:00 AM
|
|
'ai-analysis-daily': {
|
|
'task': 'apps.social.tasks.ai.analyze_pending_comments_task',
|
|
'schedule': crontab(hour=2, minute=0),
|
|
},
|
|
}
|
|
|
|
|
|
app.conf.timezone = 'Asia/Riyadh'
|
|
|
|
|
|
@app.task(bind=True, ignore_result=True)
|
|
def debug_task(self):
|
|
"""Debug task to test Celery is working."""
|
|
print(f'Request: {self.request!r}')
|