Working with Celery
Celery is a task queue for Python. Earlier, there used to be an extension to integrate Flask and Celery, but with Celery 3.0, it became obsolete. Now, Celery can be directly used with Flask by just using a bit of configuration. In the Understanding asynchronous operations recipe, we implemented asynchronous processing to send an e-mail. In this recipe, we will implement it using Celery.
Getting ready
Celery can be installed simply from PyPI:
$ pip install celery
To make Celery work with Flask, we will need to modify our Flask app config file a bit. Here, we will use Redis as the broker (thanks to its simplicity).
We will use the application from the previous recipe and implement Celery in it.
How to do it…
The first thing that we need to do is a bit of configuration in the application's configuration file, that is, my_app/__init__.py
:
from celery import Celery app.config.update( CELERY_BROKER_URL='redis://localhost:6379', CELERY_RESULT_BACKEND...