2016-04-04 73 views
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 

注 - 我想添加一個新任務而不停止芹菜。我必須使用這個第一站芹菜然後如何在芹菜中添加新任務而不停止芹菜實例在django芹菜?

celery -A HealthBrio worker -l info 

回答

1

這是一個你想要的鏈接。您可以使用django的管理界面設置crontab。 有兩種啓動任務的方式:

調度程序會在每個時間段(例如10秒)或每個特定時間(如crontab)調用任務。 來自代碼,在需要的地方,在需要的條件下。 由調度程序啓動任務 轉至地址爲http:// {host}/admin/djcelery/periodictask /的管理頁面,然後按「添加週期性任務」。

填充字段,如下面的屏幕截圖所示,然後按保存。 enter image description here

啓動週期性任務每10秒

爲了表示推出的時間,而不是一段,做同樣的,在前面的情況,但填寫的crontab(間隔必須爲空白。): enter image description here

更多詳細信息在http://www.lexev.org/en/2014/django-celery-setup/