Answer the question
In order to leave comments, you need to log in
How to implement sending a reminder to the user at the time set by him?
It is necessary to send reminders to users, the user himself chooses the date and time, he can also delete the reminder. I moved the check logic to a separate thread, where a check is performed every second in an endless loop. This thread is launched when a specific page is accessed.
def check_reminders():
while True:
# Берем самое ближайшее напоминание и сравниваем с текущим временем,
# если равны, отправляем напоминание пользователю
time.sleep(1)
def run_thread(request):
# Проверяем не запущен ли уже поток с проверкой напоминаний
for thread in threading.enumerate():
if thread.name == 'reminders_thread':
return
t1 = threading.Thread(target=check_reminders, name='reminders_thread')
t1.start()
Answer the question
In order to leave comments, you need to log in
why every second?
you can call a console command by cron and execute from it, you can install the django_cron package.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question