smarber
smarber

Reputation: 5074

Making django app notify people at specific time

Short description

How can I make my app send notification to a list of people after an amount of time that an event has been created?

Long description

My website allows Bob to put something he wants to sell online. Several persons see it and want to buy it. If after 6 hours nobody is interested in, the seller should be notified by email.

Solution I found that I think dirty

Run crontab every minute to check the whole articles that people not interesed in. Drawbacks: not too accurate+scan the whole database+external to my app ...

Is there better solutions ?

Upvotes: 1

Views: 1702

Answers (2)

Hitesh Dharamdasani
Hitesh Dharamdasani

Reputation: 862

What you are looking for is https://pypi.python.org/pypi/django-cron/0.3.6

Essentially, You use django_cron in INSTALLED_APPS as

INSTALLED_APPS = (
    'django_cron',)

Setup a cron job by creating a cron.py in your project root

class SixHourEmailUpdate(CronJobBase):
    code = 'six_hour_reminder_cron'
    schedule = Schedule( run_every_mins = 360 ) # 6 hours

    def do(self):
         # Your email sending 

Also you will have to setup a cron job with something that will run every once in a while.

*/5 * * * * bash /home/tester/my_cron/cron.sh

The cron.sh inturn calls

python /home/tester/app/my_app/manage.py runcrons

More documentation here http://django-cron.readthedocs.org/en/latest/sample_cron_configurations.html#run-at-times-feature

Upvotes: 5

Andrii Rusanov
Andrii Rusanov

Reputation: 4606

As option 1, you could write custom management command that will be used by crontab.

The option 2(actually also related to cron work) is use Celery or similar tool(in your case I prefer option 1).

Please feel free to ask questions, and I'll updated my answer

Upvotes: 2

Related Questions