You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
# ============================================
|
|
# File: bookscraper/celery_app.py
|
|
# ============================================
|
|
|
|
import os
|
|
from celery import Celery
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables (OK to do here)
|
|
load_dotenv()
|
|
|
|
print(">>> DEBUG: celery_app.py LOADED")
|
|
print(">>> DEBUG: env REDIS_BROKER =", os.getenv("REDIS_BROKER"))
|
|
print(">>> DEBUG: env REDIS_URL =", os.getenv("REDIS_URL"))
|
|
|
|
# Read broker settings
|
|
REDIS_BROKER = os.getenv("REDIS_BROKER")
|
|
REDIS_BACKEND = os.getenv("REDIS_BACKEND")
|
|
|
|
# Fallback ONLY if missing
|
|
if not REDIS_BROKER:
|
|
REDIS_BROKER = os.getenv(
|
|
"REDIS_URL", "redis://host.docker.internal:6379/0"
|
|
)
|
|
|
|
if not REDIS_BACKEND:
|
|
REDIS_BACKEND = REDIS_BROKER # safe fallback
|
|
|
|
# Create Celery app AFTER loading .env
|
|
celery_app = Celery(
|
|
"bookscraper",
|
|
broker=REDIS_BROKER,
|
|
backend=REDIS_BACKEND,
|
|
)
|
|
|
|
celery_app.conf.update(
|
|
task_default_queue="default",
|
|
task_routes={
|
|
"tasks.scraping.*": {"queue": "scraping"},
|
|
"tasks.audio.*": {"queue": "audio"},
|
|
"tasks.*": {"queue": "default"},
|
|
},
|
|
worker_prefetch_multiplier=1,
|
|
task_acks_late=True,
|
|
)
|