Skip to content

Instantly share code, notes, and snippets.

@fluffybeing
Last active August 29, 2015 14:07
Show Gist options
  • Save fluffybeing/8a131f0adffe05bd7dd3 to your computer and use it in GitHub Desktop.
Save fluffybeing/8a131f0adffe05bd7dd3 to your computer and use it in GitHub Desktop.
Create celery app in flask-app context
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