Last active
August 29, 2015 14:07
-
-
Save fluffybeing/8a131f0adffe05bd7dd3 to your computer and use it in GitHub Desktop.
Create celery app in flask-app context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import Celery | |
from app import create_app | |
def create_celery_app(app=None): | |
app = app or create_app('default') | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment