Slide 66
Slide 66 text
app.py
from init import celery
def init_celery(app=None):
app = create_app(os.getenv("FLASK_ENV", ""))
app = app or create_app()
celery.conf.update(app.config)
class ContextTask(celery.Task):
"""Make celery tasks work with Flask app context"""
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
66