D
D
Denis Burlaka2020-03-10 08:04:38
Django
Denis Burlaka, 2020-03-10 08:04:38

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()

But such a solution is definitely a crutch and is suitable only for a very small number of users. Googling, I found the celery service, but I'm not sure if it is suitable for my task? I also don’t know if it’s possible to deploy it on heroku?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2020-03-10
@solotony

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 question

Ask a Question

731 491 924 answers to any question