Spaces:
Running
Running
File size: 3,412 Bytes
3533fb9 0eeeed2 3533fb9 02c1fe3 3533fb9 cbf7ff4 3533fb9 cbf7ff4 3533fb9 0eeeed2 5414bc8 3533fb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | import socket
import sys
# Refuse execution on the specific Google Cloud instance
if socket.gethostname() == "instance-20260427-114320":
sys.exit("Error: Celery is not allowed to run on instance-20260427-114320.")
from celery import Celery
from celery.schedules import crontab
from app.core.config import REDIS_URL
celery_app = Celery(
"monteeq_worker",
broker=REDIS_URL,
# result_backend removed to save connections
include=[
"app.tasks.video_tasks",
"app.tasks.email_tasks",
"app.tasks.morning_notifications",
"app.tasks.event_tasks",
]
)
# Ensure @shared_task.delay() from FastAPI/scripts always uses this Redis broker
# (otherwise Celery falls back to amqp://localhost and enqueue silently fails).
celery_app.set_default()
celery_app.set_current()
celery_app.conf.update(
task_serializer="json",
accept_content=["json"],
result_serializer="json",
timezone="UTC",
enable_utc=True,
task_track_started=True,
task_time_limit=3600,
# Stay well under Redis Cloud free-tier ~30 concurrent clients
broker_pool_limit=2,
redis_max_connections=5,
# solo keeps Redis client count low (also required on Windows)
worker_pool="solo",
worker_concurrency=1,
broker_transport_options={
'visibility_timeout': 3600,
'max_connections': 2,
},
beat_schedule={
# Morning push notifications β daily 08:00 UTC
"morning-notifications-daily": {
"task": "tasks.morning.send_morning_notifications",
"schedule": crontab(hour=8, minute=0),
},
# Onboarding nudge check β every hour (catches D+3 and D+7 windows)
"check-onboarding-nudges": {
"task": "tasks.email.check_onboarding_nudges",
"schedule": crontab(minute=0),
},
# Inactivity ladder β hourly check (sends during local morning)
"check-inactivity": {
"task": "tasks.email.check_inactivity",
"schedule": crontab(minute=0),
},
# Weekly digest β hourly on Monday (sends during local morning)
"weekly-digest": {
"task": "tasks.email.send_weekly_digest_batch",
"schedule": crontab(minute=0, day_of_week=1),
},
# Monthly stats β 1st of every month, 10:00 UTC
"monthly-stats": {
"task": "tasks.email.send_monthly_stats_batch",
"schedule": crontab(hour=10, minute=0, day_of_month=1),
},
# Creator growth drip β hourly on Tuesday (sends during local morning)
"creator-growth-tips": {
"task": "tasks.email.send_growth_drip",
"schedule": crontab(minute=0, day_of_week=2),
},
# Social activity batch digest β daily 18:00 UTC
"flush-social-activity-batch": {
"task": "tasks.email.flush_social_batch",
"schedule": crontab(hour=18, minute=0),
},
# Video engagement events β flush every 60 seconds
"flush-video-events": {
"task": "tasks.events.flush_video_events",
"schedule": 60.0,
},
# Keep the Rust video service warm β HF Spaces sleep when idle and a
# cold start costs 30-60s on the first upload.
"warm-video-service": {
"task": "video_tasks.warm_video_service",
"schedule": 240.0,
},
},
)
|