- Morning report (8:00 AM): scheduled posts for today + new interactions - Afternoon report (6:00 PM): published count + pending interactions - Reports are sent via Telegram with formatted summaries Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
"""
|
|
Configuración de Celery para tareas en background.
|
|
"""
|
|
|
|
from celery import Celery
|
|
from celery.schedules import crontab
|
|
|
|
from app.core.config import settings
|
|
|
|
# Crear aplicación Celery
|
|
celery_app = Celery(
|
|
"social_automation",
|
|
broker=settings.REDIS_URL,
|
|
backend=settings.REDIS_URL,
|
|
include=[
|
|
"worker.tasks.generate_content",
|
|
"worker.tasks.publish_post",
|
|
"worker.tasks.fetch_interactions",
|
|
"worker.tasks.cleanup",
|
|
"worker.tasks.content_memory",
|
|
"worker.tasks.daily_reports"
|
|
]
|
|
)
|
|
|
|
# Configuración
|
|
celery_app.conf.update(
|
|
task_serializer="json",
|
|
accept_content=["json"],
|
|
result_serializer="json",
|
|
timezone="America/Tijuana",
|
|
enable_utc=True,
|
|
task_track_started=True,
|
|
task_time_limit=300, # 5 minutos máximo por tarea
|
|
worker_prefetch_multiplier=1,
|
|
worker_concurrency=2
|
|
)
|
|
|
|
# Programación de tareas periódicas
|
|
celery_app.conf.beat_schedule = {
|
|
# Generar contenido cada hora
|
|
"generate-scheduled-content": {
|
|
"task": "worker.tasks.generate_content.generate_scheduled_content",
|
|
"schedule": crontab(minute=0), # Cada hora en punto
|
|
},
|
|
|
|
# Publicar posts programados cada minuto
|
|
"publish-scheduled-posts": {
|
|
"task": "worker.tasks.publish_post.publish_scheduled_posts",
|
|
"schedule": crontab(minute="*"), # Cada minuto
|
|
},
|
|
|
|
# Obtener interacciones cada 5 minutos
|
|
"fetch-interactions": {
|
|
"task": "worker.tasks.fetch_interactions.fetch_all_interactions",
|
|
"schedule": crontab(minute="*/5"), # Cada 5 minutos
|
|
},
|
|
|
|
# Limpieza diaria a las 3 AM
|
|
"daily-cleanup": {
|
|
"task": "worker.tasks.cleanup.daily_cleanup",
|
|
"schedule": crontab(hour=3, minute=0),
|
|
},
|
|
|
|
# Actualizar engagement scores cada 6 horas
|
|
"update-engagement-scores": {
|
|
"task": "worker.tasks.content_memory.update_engagement_scores",
|
|
"schedule": crontab(hour="*/6", minute=15),
|
|
},
|
|
|
|
# Limpiar memoria antigua mensualmente
|
|
"cleanup-old-memory": {
|
|
"task": "worker.tasks.content_memory.cleanup_old_memory",
|
|
"schedule": crontab(day_of_month=1, hour=4, minute=0),
|
|
},
|
|
|
|
# Actualizar best_posts.yaml semanalmente
|
|
"refresh-best-posts": {
|
|
"task": "worker.tasks.content_memory.refresh_best_posts_yaml",
|
|
"schedule": crontab(day_of_week=0, hour=5, minute=0), # Domingos 5 AM
|
|
},
|
|
|
|
# Reporte matutino por Telegram (8:00 AM Tijuana)
|
|
"telegram-morning-report": {
|
|
"task": "worker.tasks.daily_reports.morning_report",
|
|
"schedule": crontab(hour=8, minute=0),
|
|
},
|
|
|
|
# Reporte vespertino por Telegram (6:00 PM Tijuana)
|
|
"telegram-afternoon-report": {
|
|
"task": "worker.tasks.daily_reports.afternoon_report",
|
|
"schedule": crontab(hour=18, minute=0),
|
|
},
|
|
}
|