I would like to define some celery tasks. This is my tasks.py
module:
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
The problem is, I have no access to the app
here! My app is defined in my wsgi.py
module (I am serving with gunicorn
)
from myproj.app import create_app
app = create_app()
With app.py
being:
...
def create_app():
"""
app = Flask(__name__)
...
return app
How can I access the app
singleton instance, created in the wsgi.py
module, from my tasks.py
?