mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
24 lines
669 B
Python
24 lines
669 B
Python
|
from celery import Task, Celery
|
||
|
from flask import Flask
|
||
|
|
||
|
|
||
|
def init_app(app: Flask) -> Celery:
|
||
|
class FlaskTask(Task):
|
||
|
def __call__(self, *args: object, **kwargs: object) -> object:
|
||
|
with app.app_context():
|
||
|
return self.run(*args, **kwargs)
|
||
|
|
||
|
celery_app = Celery(
|
||
|
app.name,
|
||
|
task_cls=FlaskTask,
|
||
|
broker=app.config["CELERY_BROKER_URL"],
|
||
|
backend=app.config["CELERY_BACKEND"],
|
||
|
task_ignore_result=True,
|
||
|
)
|
||
|
celery_app.conf.update(
|
||
|
result_backend=app.config["CELERY_RESULT_BACKEND"],
|
||
|
)
|
||
|
celery_app.set_default()
|
||
|
app.extensions["celery"] = celery_app
|
||
|
return celery_app
|