Skip to content

Instantly share code, notes, and snippets.

@ask
Forked from mikeywaites/async.py
Last active August 29, 2015 14:01
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 ask/195e4229e9d5f1ff6a3d to your computer and use it in GitHub Desktop.
Save ask/195e4229e9d5f1ff6a3d to your computer and use it in GitHub Desktop.
#project.async
from celery import Celery
celery = Celery(autofinalize=False)
def configure_celery(flask_app):
#...set celery up
celery.config_from_object(app.config)
class ContextTask(celery.Task):
abstract = True
def __call__(self, *args, **kwargs):
with flask_app.app_context():
return super(ContextTask, self).__call__(*args, **kwargs)
celery.Task = ContextTask
celery.finalize()
#project.__init__
create_app(*kwargs):
app = Flaks(__name__)
db.init_app(app)
configure_celery(flask_app)
#project.tasks
from project.async import celery
@celery.task
def add(x, y):
x + y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment