|
import os |
|
from celery import Celery |
|
|
|
from backend.config import Config |
|
|
|
def make_celery(app_name=__name__): |
|
"""Create and configure the Celery application.""" |
|
|
|
celery = Celery(app_name) |
|
|
|
|
|
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') |
|
|
|
|
|
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 |
|
|
|
|
|
celery = make_celery() |
|
|
|
if __name__ == '__main__': |
|
celery.start() |