Skip to content

Instantly share code, notes, and snippets.

@jezeniel
Created February 22, 2018 11:11
Show Gist options
  • Save jezeniel/fae7ecd49a96d539de2ffc93c20938e3 to your computer and use it in GitHub Desktop.
Save jezeniel/fae7ecd49a96d539de2ffc93c20938e3 to your computer and use it in GitHub Desktop.
Celery Part
from celery import Celery
from flask import Flask, jsonify, request, render_template
def make_celery(app):
celery = Celery(app.import_name,
broker=app.config['CELERY_BROKER_URL'],
backend=app.config['CELERY_RESULT_BACKEND'])
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
app = Flask(__name__)
app.config.update(
CELERY_BROKER_URL='redis://localhost:6379',
CELERY_RESULT_BACKEND='redis://localhost:6379'
)
celery = make_celery(app)
@celery.task()
def add(a, b):
return a + b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment