Skip to content

Celery Intro

Kiarash Golezardi edited this page Jan 18, 2019 · 2 revisions

First of all, see Celery: an overview of the architecture and how it works. It's a good read!

To install Celery, you can follow First steps with Celery. The broker we'll use is RabbitMQ which can be installed on macOS by:

brew install rabbitmq

if you use Homebrew as your package manager.

Installing Celery is done by:

pip install celery

You will also need to add it to your requirements.txt file. You can use pip freeze | grep celery to find the version you just installed.

Now follow First steps with Django to get your Django+Celery app started. Also this link can be a good start.

The important part is that you should set RabbitMQ broker URL in settings.py:

CELERY_MAX_RETRIES = None
CELERY_BROKER_URL = 'amqp://localhost'

In this project we are not going to need a results backend, so no need to set its URL in settings file.

Every time you change tasks.py, you should restart the workers to update according to the new code.

Creating a task for the future is done by:

task.apply_async(eta=datetime_for_the_future)
task.apply_async(countdown=cd_in_seconds)

Clone this wiki locally