Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: sending email x days later

Tags:

django

cron

In my Django project, users are allowed to register to a free trial, but if they do not complete a purchase within 15 days, their accounts are locked out until they do complete the purchase. After 13 days (ie within 48 hours or expiry) I wish to send an email the registered user reminding him/her to purchase.

Currently, I have a cron job set up to run daily and check all trial accounts if the registration date and current date are 2 days apart and if so, I send an email.

I was wondering if there is a more elegant solution to do this?

like image 340
user1161740 Avatar asked Apr 02 '12 19:04

user1161740


1 Answers

If you don't want to mess with your cron file you should check out Celery, an asynchronous task queue written in Python. It was originally created with Django in mind but has since been broken out into a separate package. What you want to do then is set up a Celerybeat schedule like this:

CELERYBEAT_SCHEDULE = {
    "purchase-reminder": {
        "task": "accounts.tasks.remind",
        "schedule": timedelta(hours=24),
    },
}

This will call the task (read: function) accounts.tasks.remind every 24 hours.

like image 178
jmagnusson Avatar answered Sep 28 '22 08:09

jmagnusson