Skip to content

Instantly share code, notes, and snippets.

@channeng
Created October 22, 2017 16:07
Show Gist options
  • Select an option

  • Save channeng/1d3005307455582e9172892f22ae007f to your computer and use it in GitHub Desktop.

Select an option

Save channeng/1d3005307455582e9172892f22ae007f to your computer and use it in GitHub Desktop.
Celery Flask setup - second step
from flask import Flask
from celery import Celery
app = Flask(__name__)
app.config.from_object('config')
def make_celery(app):
# create context tasks in celery
celery = Celery(
app.import_name,
broker=app.config['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
celery = make_celery(app)
@app.route('/')
def view():
return "Hello, Flask is up and running!"
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment