我想定义一些芹菜任务。这是我的tasks.py
模块:
from celery import Celery
def create_celery_app(app):
celery = Celery(__name__, broker=app.config['CELERY_BROKER_URL'])
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
return celery
celery = create_celery_app(app) # <--- How to access app here?
@celery.task()
def add_together(a, b):
return a + b
问题是,我无法访问app
这里!我的应用是在我的wsgi.py
模块中定义的(我正在使用gunicorn
)
from myproj.app import create_app
app = create_app()
app.py
为:
...
def create_app():
"""
app = Flask(__name__)
...
return app
如何从我的app
访问wsgi.py
模块中创建的tasks.py
单例实例?