Using the task queue for sending emails
ShipWithDjango uses Django Huey to integrate the Huey task queue, allowing you to send emails asynchronously. This means that when an email is sent, the request to send the email is placed in the task queue, and the email is sent in the background by a worker process. This approach ensures that the process of sending emails does not block the main application thread, keeping your application responsive, even under high traffic conditions.
Default Configuration
By default, ShipWithDjango is configured to use the task queue for sending emails. This is managed by the EMAIL_USE_TASK_QUEUE
variable:
EMAIL_USE_TASK_QUEUE=True
: This is the default and recommended setting. Emails are sent asynchronously using the task queue, which helps maintain the performance and responsiveness of your application.EMAIL_USE_TASK_QUEUE=False
: If set toFalse
, emails will be sent synchronously on the main thread. This means the application will wait for the email to be sent before continuing with other tasks, which can lead to delays and decreased performance, especially during high traffic periods.
When to Disable the Task Queue
While it is generally advisable to keep EMAIL_USE_TASK_QUEUE
set to True
, there may be specific scenarios where you want to disable the task queue and send emails synchronously. For example:
Debugging: If you are troubleshooting email sending and need immediate feedback, you might temporarily set
EMAIL_USE_TASK_QUEUE
toFalse
.Simplicity: In very simple or small-scale applications where the overhead of managing a task queue is unnecessary, you might choose to send emails synchronously.
However, if you do choose to disable the task queue, be aware that this can cause delays in the application’s response time, particularly if your application needs to send a large number of emails or if the email server is slow to respond.
Last updated