Reputation: 123
I am new to Django, Python and Web Development and am trying to make an RSS reader as a learning project. Now, I need help with implementing the part of regularly checking up on all channels for new content (like say every 15 mins.). I need a cron job for this and custom management commands are the way to go about it, I know that much. But I am struggling to figure out how to implement that. This link is what most people are recommending on SO, but I did not find it very helpful, like for instance, I does not explain about the scheduling for X amount of time part.
Can someone please explain, through code, how to implement checking up on channels for new content every 15 mins. Thanks in advance.
Upvotes: 2
Views: 277
Reputation: 49
Just for future refs to this, the frequency params are separated by spaces (maybe they have got lost in the posting). A good place to try out various combinations is www.dataphyx.com/cronsandbox/.
Upvotes: 0
Reputation: 174622
The "every 15 minutes" bit is the easiest actually. Once you have written the command to check it once, you set up cron to execute the command every 15 minutes.
This article has a quick overview of cron in general and how to set it up.
Things to keep in mind when running cron:
/bin/sh
) and as such do not have access to all your customizations (such as things you have added to your PATH
).python
, but rather /usr/bin/python
, or whatever is applicable to your system.mutt
is my favorite console email reader. You can set the variable MAILTO
in your cron file if you want to redirect cron results to your email.source
command won't work in cron.Once you have your management command written; just add it to your own crontab file. This file lists all the command that the system-wide cron process will execute.
To edit your crontab file, type crontab -e
from a console.
Each line in the file that isn't a comment is an entry. Entries start with the frequency, then the command to run. Here is the general format:
* * * * * command to be executed
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 7) (0 or 7 are Sunday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
An asterisk *
in any position means "all".
To run something every 15 minutes:
0/15**** /usr/bin/python /home/myuser/project/manage.py foo
Upvotes: 2