Created
July 29, 2012 21:19
-
-
Save jzempel/3201883 to your computer and use it in GitHub Desktop.
Flask with Celery (wish list)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask.ext.celery import Celery | |
from flask.ext.mail import Mail | |
celery = Celery() | |
mail = Mail() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BROKER_TRANSPORT = "mongodb" # ...or your broker of choice. | |
DEBUG = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from application import create_app | |
application = create_app() | |
application.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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..