Reputation: 159
So I have a webpage powered by Django. I have a bunch of users in a database, and I want to run a certain task on every user in the database every 5 - 10 mins. What's the best way to do this? There could be up to 1000 users at a time. Is something like Celery useful for this?
Upvotes: 4
Views: 5979
Reputation: 1852
I think below is what you want
http://code.google.com/p/django-cron/
Django - Set Up A Scheduled Job?
or you just use cron on linux level
details guide for how to setup a cron :
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
cron job in linux will run script that on predefined time interval , minutes ,hourly, daily, weekly
for details you just type "crontab -e" on your Linux terminal
crontab -e
then add up a row (task)
1 2 3 4 5 /path/to/command arg1 arg2
1: Minute (0-59) 2: Hours (0-23) 3: Day (0-31) 4: Month (0-12 [12 == December]) 5: Day of the week(0-7 [7 or 0 == sunday]) /path/to/command - Script or command name to schedule
after finish ,save and exit.
Upvotes: 1
Reputation: 731
Is something like celery usefull for this
Yes, Celery comes with built in perodic tasks: Celery Beat.
Another option would be PythonRQ in combination with RQ Scheduler. This is what I've used in a recent project and I am very happy with it.
Upvotes: 2
Reputation: 21918
"Celery" lets Python apps (like Django) run background processes easily. It was actually originally built specifically for Django.
Their example showing a simple task adding two numbers:
from celery.decorators import task
@task
def add(x, y):
return x + y
You can execute the task in the background, or wait for it to finish:
>>> result = add.delay(8, 8)
>>> result.wait() # wait for and return the result
16
Here's info on "cron"-like scheduled tasks: http://docs.celeryproject.org/en/latest/reference/celery.schedules.html
You'll probably want to install RabbitMQ also to get it working, so it might be more complicated of a solution than you're looking for, but it will achieve your goals. There are also lighterweight ways to install it if you like (including using the DB itself) and if you understand the limitations.
Upvotes: 0