简体   繁体   中英

Schedule emails on a specific time using Django and celery

This is the use case I am looking for:

  • User will register on my application
  • It is a note making and remainder application
  • While creating remainder users will enter the time my application wants to send user an email at that time
  • I have to use celery for the same I read several posts and stack overflow answers but didn't get proper answer for the same.

My application is written in Django.

When a user creates a new reminder just schedule a send email task in celery. Note that this is a simple solution but it will make it hard for the user to change notification time after creating it.

From this answer :

To execute a task at a specified date and time you can use eta attribute of apply_async while calling task as mentioned in docs

your_task.apply_async(kwargs={}, eta="your_send_time")

A different solution is to have a task running every 1 minute which will check in DB if there are any emails to be sent. You don't have to use Celery for that. Cron-like lib should do the trick. For example schedule lib or django-cron or Django Commands


Edit: this guy says you should not use dbader/schedule with Django.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM