24 lines
827 B
Python
24 lines
827 B
Python
from .tasks import create_embeddings
|
|
from celery import Celery, Task
|
|
|
|
|
|
def init_celery(app):
|
|
class ContextTask(Task):
|
|
def __call__(self, *args, **kwargs):
|
|
with app.app_context():
|
|
return self.run(*args, **kwargs)
|
|
|
|
celery_app = Celery(app.import_name, task_cls=ContextTask)
|
|
|
|
celery_app.conf.broker_url = app.config.get('CELERY_BROKER_URL')
|
|
celery_app.conf.result_backend = app.config.get('CELERY_RESULT_BACKEND')
|
|
celery_app.conf.accept_content = app.config.get('CELERY_ACCEPT_CONTENT')
|
|
celery_app.conf.task_serializer = app.config.get('CELERY_TASK_SERIALIZER')
|
|
celery_app.conf.timezone = app.config.get('CELERY_TIMEZONE')
|
|
celery_app.conf.enable_utc = app.config.get('CELERY_ENABLE_UTC')
|
|
|
|
celery_app.set_default()
|
|
|
|
app.extensions['celery'] = celery_app
|
|
|