Skip to content

Instantly share code, notes, and snippets.

@mikeywaites
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikeywaites/383ef6c552f8e8f20cb7 to your computer and use it in GitHub Desktop.
Save mikeywaites/383ef6c552f8e8f20cb7 to your computer and use it in GitHub Desktop.
#project.async
celery = None
def make_celery(app):
#...set celery up
global celery
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
#project.__init__
create_app(*kwargs):
app = Flaks(__name__)
db.init_app(app)
make_celery(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