speg
speg

Reputation: 2019

How to queue up scheduled actions

I am trying to set up some scheduled tasks for a Django app with celery, hosted on heroku. Aside from not know how everything should be configured, what is the best way to approach this?

Let's say users can opt to receive a daily email at a time of their choosing.

Should I have a scheduled job that run every, say 5 minutes. Looks up every user who wants to be emailed at that time and then fire off the emails?

OR

Schedule a task for each user, when they set their preference. (Not sure how I would actually implement this yet)

Upvotes: 0

Views: 234

Answers (2)

Goro
Goro

Reputation: 10249

I would suggest the first option (scheduled job that looks up outstanding jobs) - easier to scale and manage. What if you have 1000s of users - that is a lot of tasks JUST for sending emails.

If you use your database as celery broker, you can use django-celery's built in cron-like scheduling, which would allow you to create and destroy tasks dynamically. I don't like using the DB for my broker, though.

Also, you might want to check out chronos

Upvotes: 0

Thomas
Thomas

Reputation: 11888

It depends on how much accuracy you need. Do you want users to select the time down to the minute? second? or will allowing them to select the hour they wish to be emailed be enough.

If on the hour is accurate enough, then use a task that polls for users to mail every hour.

If your users need the mail to go out accurate to the second, then set a task for each user timed to complete on that second.

Everything in between comes down to personal choice. What are you more comfortable doing, and even more importantly: what produces the simplest code with the fewest failure modes?

Upvotes: 1

Related Questions