Lin / backend /celery_app.py
Zelyanoth's picture
tg
b29b905
raw
history blame
1.18 kB
import os
from celery import Celery
# Use relative import for the Config class to work with Hugging Face Spaces
from backend.config import Config
def make_celery(app_name=__name__):
"""Create and configure the Celery application."""
# Create Celery instance
celery = Celery(app_name)
# Configure Celery with broker and result backend from environment variables
celery.conf.broker_url = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379/0')
celery.conf.result_backend = os.environ.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0')
# Additional Celery configuration
celery.conf.update(
task_serializer='json',
accept_content=['json'],
result_serializer='json',
timezone='UTC',
enable_utc=True,
task_routes={
'celery_tasks.content_tasks.generate_content': {'queue': 'content'},
'celery_tasks.publish_tasks.publish_post': {'queue': 'publish'},
},
worker_prefetch_multiplier=1,
task_acks_late=True,
)
return celery
# Create the Celery instance
celery = make_celery()
if __name__ == '__main__':
celery.start()