Files
social-media-automation/app/worker/celery_app.py
Consultoría AS edc0e5577b feat(phase-4): Complete scheduling and automation system
- Add Celery worker with 5 scheduled tasks (Beat)
- Create ContentScheduler for optimal posting times
- Add calendar endpoints for scheduled posts management
- Implement Telegram notification service
- Add notification API with setup guide

Celery Beat Schedule:
- check_scheduled_posts: Every minute
- generate_daily_content: Daily at 6 AM
- sync_interactions: Every 15 minutes
- send_daily_summary: Daily at 9 PM
- cleanup_old_data: Weekly on Sundays

New endpoints:
- GET /api/calendar/posts/scheduled - List scheduled posts
- GET /api/calendar/posts/view - Calendar view
- GET /api/calendar/posts/slots - Available time slots
- POST /api/calendar/posts/{id}/schedule - Schedule post
- POST /api/calendar/posts/{id}/publish-now - Publish immediately
- GET /api/notifications/status - Check notification config
- POST /api/notifications/test - Send test notification
- GET /api/notifications/setup-guide - Configuration guide

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 01:56:10 +00:00

77 lines
1.9 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
},
# 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
},
},
)