1👍
✅
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.
Source:stackexchange.com