Skip to main content

simple Python library based on rq to store emails sent by Django and process them in the background with workers

Project description

django-rq-mail is a simple Python library based on rq to store emails sent by Django and process them in the background with workers.

As django-rq-mail is based on rq, it’s entirely backed by Redis.


django-rq-mail adds new elements to enjoy Sorted Sets from Redis.

For the purpose of django-rq-mail, it implements the concept of WaitingQueue which delays the processing of a job with a timestamp.

The default behavior of rq is to process jobs via BLPOP which blocks the connection when there are no elements to pop from any of the given queues. With this behavior there is no way to delays the processing of a job and when it’s failing rq pushs it in a failed queue. Of course, you can requeue this job later but there is no fallback mechanism.

In django-rq-mail you can define fallback steps (in seconds) to retry a job until it’s not failing. When a job has been tested on each steps we reintroduce the default behavior of rq on pushing it in the failed queue.

Each steps will create a waiting queue and when a job is failing we take the current timestamp with the delta to retry it in the future.

This mechanism is possible with ZADD which adds a serialized job in the queue with a score and ZREVRANGEBYSCORE to return all the elements in the sorted set with a score between max (current timestamp) and min.

As you may understood, we have dropped the default blocking behavior to replace it by a daemon which is running each seconds.


  1. Either check out the package from GitHub or it pull from a release via PyPI

    pip install django-rq-mail
  2. Add ‘rq_mail’ to your INSTALLED_APPS


to use the rq_mail command (via Django commandline) shipped by django-rq-mail.

This command is a minimal integration of rq into Django to launch the Dispatcher.


    EMAIL_BACKEND = 'rq_mail.backends.RqBackend'
  2. Define RQ_MAIL_EMAIL_BACKEND the backend used to send your emails, for example

    RQ_MAIL_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'


Once you have installed it, you can run python rq_mail from your shell.



The prefix used to name all queues created by django-rq-mail.


The name of the main queue.


The email backend used to send emails when they are processed in the background.


The Redis host used to connect.


The Redis port used to connect.


The Redis database used to connect.


The Redis password used to connect.


A simple list of timing to create waiting queues.

You can define as much steps as you want, each will be transformed to a queue. So if you define 10 steps, you will allow a message to fail 10 times until it will go in the failed queue.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-rq-mail-0.1.alpha.tar.gz (7.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page