Skip to content

Instantly share code, notes, and snippets.

@yuriwoof
Created September 16, 2017 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriwoof/3b92f9bdd1d047563f7e0cf634b9d505 to your computer and use it in GitHub Desktop.
Save yuriwoof/3b92f9bdd1d047563f7e0cf634b9d505 to your computer and use it in GitHub Desktop.
from celery import Celery
def make_celery(app):
celery = Celery(app.import_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