0

I am new to Django. I built a program that lets teachers assign homework to students. The homework has a due date that is different for each student.

I want to make it so that 1 hour before the homework is due for that particular student, they get sent an email.

So, for example:

  • Student 1 with HW due at 3 pm would get an email at 2 pm
  • Student 2 with HW due at 1 am would get an email at 12 am

How can I achieve this? Thanks!!!

2 Answers2

0

You could use something like Celery to define a task or a list of tasks to be done.

Also you could use django-background-tasks module to schedule a task.

rahimz
  • 23
  • 1
  • 7
  • Thank you so much for your answer! I've come across `Celery`, `django-background-tasks`, `django-cron`, `django-crontab` and many more. Do you know which one is best for this task? So far I've seen `Celery` be most recommended. Thanks!! –  Aug 23 '20 at 05:32
  • I think celery is the most useful however it's a bit complicated. – rahimz Aug 24 '20 at 05:26
0

write a Django Management command which identifies students who need to be sent a reminder email and then sends emails. use cron job(crontab in Linux) to run this Django management command periodically (every hour or every minute)

Neeraj
  • 783
  • 5
  • 8
  • I see. Thanks so much for your response! How come you would recommend this over Celery? –  Aug 23 '20 at 05:47
  • Celery is excellent, I use it my self , but it has a steep learning for setting up tasks, also you will be need to use message broker to send tasks to celery and additional utility to run celery in daemon mode. – Neeraj Aug 23 '20 at 05:57
  • I see, thanks for the advice. By the way, I am running this on AWS Elastic Beanstalk. Will Django Management Command work with that? –  Aug 23 '20 at 06:00
  • I have not used AWS Elastic Beanstalk before , but I am guessing the answer should be yes ,because cron jobs are part of basic functionality and i will be surprised if they are not supported. – Neeraj Aug 23 '20 at 06:16
  • Ok, while you're here. Could you link some good tutorials for this? I can't seem to find too many that have my use case. Or maybe even write an answer with code. Thanks!! –  Aug 23 '20 at 06:25
  • stack overflow is for asking for help , not for outsourcing your work to others. – Neeraj Aug 23 '20 at 08:44
  • My bad. Thanks for the help! –  Aug 23 '20 at 17:37