1
Guys is the following, in Django things only happen when some user accesses your application.
AN EXAMPLE (fictional)
Let’s imagine that you created an application in which the user enters and records small reminder texts, more or less as if they were a post-it, for him to consult every day and check the activities that can not forget.
The user needs to enter the application to consult their reminders for the current date and to add new reminders for future dates.
THE NEW NEED
Now imagine that you want to implement a new functionality so that every day your application sends an email listing of user reminders for that starting day.
THE REFLECTION ON THE CASE
Note that originally all actions that occur in the application depend on a user access, but for this new functionality we will need the system to initiate an action automatically without waiting for a user action.
It would be a kind of service running that every day at a certain time check the reminders of each user, prepare each message and send them.
WHAT I THOUGHT TO DO
It crossed my mind to create a thread that runs all the time in parallel and when arriving at the scheduled time triggers the necessary routines.
It seems to make some sense, but I’m not sure if there is a better option to do this and still what the pros and cons of this structure would be, plus some possible impact on the system’s resource consumption.
Important: I have no difficulty in preparing the routines they perform actions (check reminders, prepare messages and send emails), my problem is about how to create that schedule that will trigger this process automatically.
You already had to create something like this with Django, as you did?
The ideal is to schedule a task in the OS (e.g., on *NIX systems, via cron) that calls a Django command (e.g..: via
manage.py
) which then does what you want. Or else use a tool like the Celery (never used, but what I’ve been researching is the most recommended way to do it). P.S. I do not give a more complete answer because I have no practical experience.– mgibsonbr