Phase 1 - Analytics y Reportes: - PostMetrics and AnalyticsReport models for tracking engagement - Analytics service with dashboard stats, top posts, optimal times - 8 API endpoints at /api/analytics/* - Interactive dashboard with Chart.js charts - Celery tasks for metrics fetch (15min) and weekly reports Phase 2 - Integración Odoo: - Lead and OdooSyncLog models for CRM integration - Odoo fields added to Product and Service models - XML-RPC service for bidirectional sync - Lead management API at /api/leads/* - Leads dashboard template - Celery tasks for product/service sync and lead export Phase 3 - A/B Testing y Recycling: - ABTest, ABTestVariant, RecycledPost models - Statistical winner analysis using chi-square test - Content recycling with engagement-based scoring - APIs at /api/ab-tests/* and /api/recycling/* - Automated test evaluation and content recycling tasks Phase 4 - Thread Series y Templates: - ThreadSeries and ThreadPost models for multi-post threads - AI-powered thread generation - Enhanced ImageTemplate with HTML template support - APIs at /api/threads/* and /api/templates/* - Thread scheduling with reply chain support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
131 lines
3.8 KiB
Python
131 lines
3.8 KiB
Python
"""
|
|
Celery application configuration.
|
|
"""
|
|
|
|
from celery import Celery
|
|
from celery.schedules import crontab
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
# Create Celery app
|
|
celery_app = Celery(
|
|
"social_automation",
|
|
broker=settings.REDIS_URL,
|
|
backend=settings.REDIS_URL,
|
|
include=[
|
|
"app.worker.tasks",
|
|
]
|
|
)
|
|
|
|
# Celery configuration
|
|
celery_app.conf.update(
|
|
# Serialization
|
|
task_serializer="json",
|
|
accept_content=["json"],
|
|
result_serializer="json",
|
|
|
|
# Timezone
|
|
timezone="America/Tijuana",
|
|
enable_utc=True,
|
|
|
|
# Task settings
|
|
task_track_started=True,
|
|
task_time_limit=300, # 5 minutes max per task
|
|
task_soft_time_limit=240, # Soft limit 4 minutes
|
|
|
|
# Result backend settings
|
|
result_expires=86400, # Results expire after 24 hours
|
|
|
|
# Worker settings
|
|
worker_prefetch_multiplier=1,
|
|
worker_concurrency=4,
|
|
|
|
# Beat schedule for periodic tasks
|
|
beat_schedule={
|
|
# Check and publish scheduled posts every minute
|
|
"check-scheduled-posts": {
|
|
"task": "app.worker.tasks.check_scheduled_posts",
|
|
"schedule": 60.0, # Every minute
|
|
},
|
|
|
|
# Check and publish thread series posts every minute
|
|
"check-thread-schedules": {
|
|
"task": "app.worker.tasks.check_thread_schedules",
|
|
"schedule": 60.0, # Every minute
|
|
},
|
|
|
|
# Generate daily content at 6 AM
|
|
"generate-daily-content": {
|
|
"task": "app.worker.tasks.generate_daily_content",
|
|
"schedule": crontab(hour=6, minute=0),
|
|
},
|
|
|
|
# Sync interactions every 15 minutes
|
|
"sync-interactions": {
|
|
"task": "app.worker.tasks.sync_interactions",
|
|
"schedule": crontab(minute="*/15"),
|
|
},
|
|
|
|
# Send daily summary at 9 PM
|
|
"send-daily-summary": {
|
|
"task": "app.worker.tasks.send_daily_summary",
|
|
"schedule": crontab(hour=21, minute=0),
|
|
},
|
|
|
|
# Cleanup old data weekly
|
|
"cleanup-old-data": {
|
|
"task": "app.worker.tasks.cleanup_old_data",
|
|
"schedule": crontab(hour=3, minute=0, day_of_week=0), # Sunday 3 AM
|
|
},
|
|
|
|
# Fetch post metrics every 15 minutes
|
|
"fetch-post-metrics": {
|
|
"task": "app.worker.tasks.fetch_post_metrics",
|
|
"schedule": crontab(minute="*/15"),
|
|
},
|
|
|
|
# Generate weekly analytics report on Sunday at 9 AM
|
|
"generate-weekly-report": {
|
|
"task": "app.worker.tasks.generate_weekly_analytics_report",
|
|
"schedule": crontab(hour=9, minute=0, day_of_week=0), # Sunday 9 AM
|
|
},
|
|
|
|
# Recalculate optimal times weekly on Monday at 2 AM
|
|
"recalculate-optimal-times": {
|
|
"task": "app.worker.tasks.recalculate_optimal_times",
|
|
"schedule": crontab(hour=2, minute=0, day_of_week=1), # Monday 2 AM
|
|
},
|
|
|
|
# Sync products from Odoo daily at 6 AM
|
|
"sync-products-odoo": {
|
|
"task": "app.worker.tasks.sync_products_from_odoo",
|
|
"schedule": crontab(hour=6, minute=0),
|
|
},
|
|
|
|
# Sync services from Odoo daily at 6:05 AM
|
|
"sync-services-odoo": {
|
|
"task": "app.worker.tasks.sync_services_from_odoo",
|
|
"schedule": crontab(hour=6, minute=5),
|
|
},
|
|
|
|
# Export leads to Odoo every hour
|
|
"export-leads-odoo": {
|
|
"task": "app.worker.tasks.export_leads_to_odoo",
|
|
"schedule": crontab(minute=30), # Every hour at :30
|
|
},
|
|
|
|
# Evaluate A/B tests every hour
|
|
"evaluate-ab-tests": {
|
|
"task": "app.worker.tasks.evaluate_ab_tests",
|
|
"schedule": crontab(minute=0), # Every hour at :00
|
|
},
|
|
|
|
# Auto-recycle content daily at 2 AM
|
|
"auto-recycle-content": {
|
|
"task": "app.worker.tasks.auto_recycle_content",
|
|
"schedule": crontab(hour=2, minute=0),
|
|
},
|
|
},
|
|
)
|