File size: 1,178 Bytes
25f22bf b29b905 25f22bf |
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 |
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() |