Forums

When to use task for email

Reading https://blog.pythonanywhere.com/198/ Do you recommend using an always-on task to send emails? Or is that useless?

It pretty much depends on your use case, so it's hard to give any advice without having more context.

Users receive emails for both notifications and password-reset links. Right now the amount is in the (extremely low) range of <10 per day, but could increase or face spikes in the future, so we want to understand at what range we could need to switch to always-on-tasks.

The idea of pulling out some jobs from views to an external (from the point of view of the web app) queue is when a job would take too much time and block the processing of a request, thus makings the request slow, which is inconvenient for the end user and is blocking workers on your web app (affecting its performance). If emails are to be sent in response of user actions and the email sending is a long process, I'd consider using a queue, otherwise it may not be needed -- but please don't treat that as an oracle. You can always start with simple processing in the views, and move things away to the task, when it needs scaling and the mail processing would seem a performance killer. Also, if it's not critical to send emails immediately after some user action, creating an external queue and processing it in batches from time to time could be an option, too. From the point of view of PythonAnywhere "economics" -- with Alwyas-on tasks you need to consider CPU seconds used by the processing; with web app alone, the number of available workers.