Почитал
slides.skien.cc/flask-hacks-and-best-practices/#17
Запихал инициализацию в
autoapp.py:
# -*- coding: utf-8 -*-
"""Create an application instance."""
from flask.helpers import get_debug_flag
from myapp.app import create_app
from myapp.settings import DevConfig, ProdConfig
from myapp.extensions import celery
from myapp.utils import init_celery
CONFIG = DevConfig if get_debug_flag() else ProdConfig
app = create_app(CONFIG)
init_celery(app, celery)
util.py:
def init_celery(app, celery):
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
Запустил
celery worker --app=autoapp.celery --loglevel=debug