Reputation: 703
I am wanting to send notifications based on a user-specified time. IE, in google calendar, I can receive a text message when my task time is hit.
Is the solution to this to run a cron job, have it execute every minute and scan which users have a time equaling the current time?
Upvotes: 0
Views: 275
Reputation: 2945
Since you tagged your question with celery
, I assume you have celery running. You could use the eta
kwarg to apply_async()
to schedule a task to run at a specific time, see here:
http://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown
If you need to use a cron job, I would not check if notification_time == current_time
, but rather track unsent notifications with a boolean is_sent
field on the model and check for notification_time <= current_time and not is_sent
. This seems to be slightly less error prone. You could also add some form of check to prevent mass-sending notifications in case your system goes down for a few hours.
Upvotes: 1