-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flask-Celery no longer needed for Celery 3.0
- Loading branch information
Showing
2 changed files
with
56 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,71 @@ | ||
============================== | ||
Flask <-> Celery Integration | ||
============================== | ||
:Version: 2.4.1 | ||
:Version: 2.4.3 | ||
|
||
Requires `Celery`_ 2.3.0 or later, and Flask 0.8 or later. | ||
**FROM CELERY 3.0 THIS LIBRARY IS NO LONGER NECESSARY, INSTEAD YOU SHOULD | ||
USE THE STANDARD CELERY API** | ||
|
||
.. _Celery: http://celeryproject.org | ||
|
||
Installation Celery | ||
=================== | ||
Using Flask with Celery | ||
======================= | ||
|
||
You can install Celery either via the Python Package Index (PyPI) or from source. | ||
From Celery 3.0 the Flask-Celery integration package is no longer | ||
recommended and you should use the standard Celery API instead. | ||
|
||
To install using pip: | ||
Please read the Celery getting started tutorial:: | ||
|
||
$ pip install Celery | ||
http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html | ||
|
||
To install using easy_install: | ||
|
||
$ easy_install Celery | ||
You can easily add Celery to your flask application like this:: | ||
|
||
To install from source: | ||
:: | ||
$ tar xvfz celery-0.0.0.tar.gz | ||
$ cd celery-0.0.0 | ||
$ python setup.py build | ||
# python setup.py install (root user) | ||
``myapp.py``:: | ||
|
||
Example | ||
======= | ||
from celery import Celery | ||
|
||
You probably want to see some code by now, so you can see example/ for example usage (task | ||
adding two numbers): | ||
:: | ||
python manage.py celeryd | ||
python myapp.py | ||
celery = Celery('myapp', broker='amqp://guest@localhost//') | ||
|
||
Check http://127.0.0.1:5000/ | ||
@celery.task | ||
def add(x, y): | ||
return x + y | ||
|
||
|
||
To start the worker you can then launch the ``celery worker`` command | ||
by pointing to your ``celery`` app instance:: | ||
|
||
$ celery -A myapp worker -l info | ||
|
||
(if the app argument (``-A|--app)`` is a module/package instead of an | ||
attribute | ||
it will automatically expand into ``myapp.celery``) | ||
|
||
|
||
See the commands help screen for more information:: | ||
|
||
$ celery help | ||
|
||
|
||
If you want use the flask configuration as a source for the celery | ||
configuration you can do that like this:: | ||
|
||
celery = Celery('myapp') | ||
celery.config_from_object(flask_app.config) | ||
|
||
|
||
If you need access to the request inside your task | ||
then you can use the test context:: | ||
|
||
from flask import Flask | ||
from celery import Celery | ||
|
||
app = Flask('myapp') | ||
celery = Celery('myapp') | ||
|
||
celery.config_from_object(app.config) | ||
|
||
@celery.task | ||
def hello(): | ||
with app.test_request_context() as request: | ||
print('Hello {0!r}.format(request)) |
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