0
@shared_task
def forgot_email(subject,user_cipher,key_cipher,to):
   print "comes here in the mail"
   try:
      email_content = {'user_cipher':user_cipher,'key_cipher':  key_cipher}
      message = render_to_string('forgot_password.txt',email_content)
      send_mail(subject, message, settings.EMAIL,to, fail_silently=False) 
      except Exception,e:
      print "Exception",e
    except:
       print 'exp'

@shared_task
def multiplesendmail(subject,body,first_name,to):
    print "comes here in the mail"
    try:
        print 'subject',subject,'body',body,'first_name',first_name,'to',to
        # email_content = {'first_name':first_name,'user_cipher':user_cipher,'key_cipher':key_cipher}
        # message = render_to_string('email_verification.txt', email_content)
        send_mail(subject,body,settings.EMAIL,to,fail_silently=False) 
    except Exception,e:
        print "Exception",e

注-セロリを停止せずに新しいタスクを追加したい。この最初のストップ セロリを使用する必要があります。

celery -A HealthBrio worker -l info
4

1 に答える 1

1

これはあなたが望むもののリンクです。django の管理インターフェースを使用して crontab をセットアップできます。タスクを開始するには、次の 2 つの方法があります。

スケジューラによって、一定期間ごと (たとえば 10 秒) または特定の時間ごと (crontab のように) にタスクが呼び出されます。コードから、必要な場所で、必要な条件下で。スケジューラーによるタスクの起動 アドレス http://{host}/admin/djcelery/periodictask/ の管理ページに移動し、「定期タスクの追加」を押します。

以下のスクリーンショットに示されているようにフィールドに入力し、保存を押します。 ここに画像の説明を入力

定期的なタスクを 10 秒ごとに起動する

期間の代わりに起動時間を示すには、前の場合と同じように行いますが、Crontab を入力します (間隔は空白にする必要があります)。 ここに画像の説明を入力

詳細については、http://www.lexev.org/en/2014/django-celery-setup/を参照してください。

于 2016-04-04T06:52:39.757 に答える