def make_celery(app):
"""Create a celery instance for the application."""
# Celery is optional, import it here rather than globally
from celery import Celery
celery_instance = Celery(
app.import_name,
backend=app.config['CELERY_RESULT_BACKEND'],
broker=app.config['CELERY_BROKER_URL']
)
celery_instance.conf.update(app.config)
TaskBase = celery_instance.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery_instance.Task = ContextTask
return celery_instance
评论列表
文章目录