# Scheduling emails with celery in Django

DevFeed: [Scheduling emails with celery in Django](<https://devfeed.tech/articles/scheduling-emails-with-celery-in-django-19981.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2013/06/05/scheduling-emails-with-celery-in-django/>)

Published: 2013-06-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [Django](<https://devfeed.tech/topics/django.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [configuration](<https://devfeed.tech/tags/configuration.md>), [django](<https://devfeed.tech/tags/django.md>), [github](<https://devfeed.tech/tags/github.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [production](<https://devfeed.tech/tags/production.md>), [queue](<https://devfeed.tech/tags/queue.md>), [rabbitmq](<https://devfeed.tech/tags/rabbitmq.md>)

## AI overview

This tutorial explains how to use Django-Celery to schedule email-sending tasks asynchronously. It covers Celery brokers and workers, RabbitMQ, production worker configuration, and storing scheduled task identifiers for model instances.

## Source excerpt

After a long journey with Django, you come to a place where you feel the need to get some tasks done asynchronously without any supervision of human. Some tasks need to be scheduled to run once at a particular time or after some time and some tasks have to be run periodically like crontab. One of the tasks is sending emails on specific triggers. Here at HackerEarth , one of the major chunk of emails is sent to recruiters and participants after a contest is finished or when participant triggers finish-test button. Till now we had done this using crontab. But things have changed now and scaling with such process is time and resource consuming. Also, looking in to database if there is any task that has to be done with crontab process is not a good method, atleast for those tasks those have to run only once in the lifetime. ####Django-Celery Django-Celery comes to the rescue here. Celery gets tasks done asynchronously and also supports scheduling of tasks as well. Integrating Celery with Django codebase is easy enough, you just need to have some patience and go through the steps given in the official Celery site. There are two sides in Celery technology: Broker & Worker. Celery requires a solution to send and receive messages, usually this comes in the form of a separate service called a message broker. We use the default broker RabbitMQ to get this done. Worker fetches the tasks from the queue at time at which they were scheduled to run asynchronously. You will have to download celery init scripts to run the worker as daemon on Production. You can get those init scripts from GitHub This is the configuration we used to run celery in our project: # Name of nodes to start CELERYD_NODES="w1 w2 w3" # Where to chdir at start. CELERYD_CHDIR="/hackerearth/" # How to call "manage.py celeryd_multi" CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi" # How to call "manage.py celeryctl" CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl --settings=settings.hackerearth_settings" # Ex