Working with Celery
Celery is a task queue for Python. 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 email. In this recipe, we will implement the same 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. In order to do its job, Celery needs a broker to receive and deliver tasks. Here, we will use Redis as the broker (thanks to its simplicity).
Information
Make sure that you run the Redis server for the connection to happen. To install and run a Redis server, refer to https://redis.io/docs/getting-started/.
You would also need to install the Redis client in your virtual environment:
$ pip
install Redis...