0

I am using rq scheduler. I want to remind users to verify their email after 2 mins and 10 mins. So I use post_save signal to schedule these tasks. I have set up task like this:

from datetime import timedelta
import django_rq
def send_verification_email(user):
"""Remind signed up user to verify email."""
   
    if not user.is_email_verified:
        context = get_email_context(user)
        context['first_name'] = user.first_name
        context['url'] = django_settings.ACTIVATION_URL.format(**context)
        # below line sends email
        VerifyEmailReminderNotification(user.email, context=context).send()

@receiver(post_save)
def remind_to_verify_email(sender, created, instance, **kwargs):
    """Send verify email for the new user."""
    list_of_models = ('Person', 'Company')
    scheduler = django_rq.get_scheduler("default")
    if sender.__name__ in list_of_models:
        if created:
            scheduler.enqueue_in(timedelta(minutes=2), send_verification_email, instance)
            # if I move below enqueue to "send_verification_email" method it will go to recursion.
            scheduler.enqueue_in(timedelta(minutes=10), send_verification_email, instance)

Problem is: I am getting one mail after 2 mins but not second mail after 10 mins. Any help appreciated.

Community
  • 1
  • 1
Kishan Mehta
  • 2,598
  • 5
  • 39
  • 61

1 Answers1

1

Run first task with delta 2 minutes and when it executes, it should run another one with delta 8 minutes. Hope that helps.

turkus
  • 4,637
  • 2
  • 24
  • 28
  • Thanks but Whatever delta I set for second task it does not execute the function it is supposed to. P.S I waited 15 mins for the second mail still not there. – Kishan Mehta Aug 22 '16 at 09:08
  • Yes, I understand, I'm just giving you another option to achieve the same result, without thinking why when you execute to tasks at once one doesn't run. – turkus Aug 22 '16 at 09:14
  • Oh okay. got it you mean I should put my second "scheduler.enqueue" in my send_verification_mail method ! I will try that Thanks . – Kishan Mehta Aug 22 '16 at 09:29
  • But first task ran? And in body of first task you scheduled next one? – turkus Aug 22 '16 at 12:28
  • Actually it will go to recursion. I have update question which shows my function to invoke. – Kishan Mehta Aug 22 '16 at 14:26
  • Ok, but you still invoke two ``enqueue_in`` one after another as I see, is that right or code is outdated? – turkus Aug 22 '16 at 15:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121579/discussion-between-soup-boy-and-turkus). – Kishan Mehta Aug 23 '16 at 02:55