Skip to content

Instantly share code, notes, and snippets.

@jzempel
Created July 29, 2012 21:19
Show Gist options
  • Save jzempel/3201883 to your computer and use it in GitHub Desktop.
Save jzempel/3201883 to your computer and use it in GitHub Desktop.
Flask with Celery (wish list)
from blueprint import example
from extensions import celery, mail
from flask import Flask
import settings
def create_app(settings=settings):
ret_val = Flask(__name__)
ret_val.config.from_object(settings)
# initialize extensions...
celery.init_app(ret_val)
mail.init_app(ret_val)
# register blueprints...
ret_val.register_blueprint(example)
return ret_val
from flask import Blueprint
from tasks import handle_notification
example = Blueprint("example", __name__)
@example.route('/')
def notify():
ret_val = "Hello World!"
handle_notification.apply_async([ret_val])
return ret_val
from flask.ext.celery import Celery
from flask.ext.mail import Mail
celery = Celery()
mail = Mail()
BROKER_TRANSPORT = "mongodb" # ...or your broker of choice.
DEBUG = True
from extensions import celery, mail
from flask.ext.mail import Message
@celery.task
def handle_notification(body):
message = Message("Test")
message.body = body
with mail.connect() as connection:
connection.send(message)
from application import create_app
application = create_app()
application.run()
@shadowing
Copy link

Hi, I just met your post in celery-users mailing list which directed me here. I happen to have the same problem and wish like you!

I have to ask blatantly that have you made any progress over this? I cannot find many useful information about celery-flask integration after celery 3.0 anywhere..

@ivanrvpereira
Copy link

Hi @shadowing, i have the same sort of questions. Have you made any progress? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment