2015-05-20 50 views
2

我想弄清楚如何自動發送適當任務的電子郵件通知。如何自動發送電子郵件作爲提醒

我有一個任務的到期日期,我希望它在指定的日期發送它,但在它到期前1小時。

I'have了創建自定義命令

notify.py

class Command(BaseCommand): 
    help = 'Email notification' 

    def handle(self, *args, **options): 
     Job.generate_emails() 

models.py

@classmethod 
    def generate_emails(cls): 
     pass 

這就是I'have迄今所做。

+1

使用芹菜。 http://celery.readthedocs.org/en/latest/ – ruddra

+1

我會建議https://github.com/arteria/django-background-tasks – taesu

回答

1

對於簡單的任務,我寧願做一個小的custom admin command並在服務器上添加一個cron作業。

如果任務的重複性不夠,可以添加一個額外的命令,該命令將頻繁運行並清除一個小任務隊列,以檢查是否要發送電子郵件。

另外還有一些軟件包,比如Celery,因爲@ ruddra已經很好地指出了(我上次檢查時Celery不支持Python 3.4)。

+0

非常感謝! – nope