簡體   English   中英

Django rq調度程序無法使同一任務兩次入隊

[英]Django rq scheduler can not enqueue same task twice

我正在使用rq調度程序 我想提醒用戶在2分鍾和10分鍾后驗證他們的電子郵件。 因此,我使用post_save信號來計划這些任務。 我已經設置了這樣的任務:

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)

問題是:2分鍾后我收到一封郵件,但是10分鍾后我沒有收到第二封郵件。 任何幫助表示贊賞。

以增量2分鍾運行第一個任務,執行該任務時,應以增量8分鍾運行另一個任務。 希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM