Plan – Cron jobs in Python
github.com
github.com
1. You can validate cron jobs and programmatically change or reject some of them. Or maybe just offer a small set of services as a cron job.
2. Once you have a security model you can expose this as a web service and offer cron jobs over the web.
3. You could extend this API to use different implementations of cron. Instead of calling the actual cron you could implement cron in Python or maybe use a cron web service.
$ crontab -e
crontab: installing new crontab
"/tmp/crontab.QhkOLb/crontab":25: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n)
2. See better solutions (like Celery) below. crontab -l
for listing crontab -e
for editing. What else do you need?With this, instead of learning crontab simple syntax, you need to:
- install this package
- learn its API
- run it and still edit the crontab file :D
seems like not worth it.
If it's because users can only have a single crontab, you can always use system crontabs instead or "cat" them together.
$ crontab [ -u user ] fileFor instance, server side exponential backoff.
That said, cron is easy to abuse as well. The example of providing exponential backoff is kind of silly: there are better tools for the job, including Celery. Cron also does not have seconds precision which is a bummer for lots of short-lived jobs. Lastly, cron only runs jobs at the specified time. If you adjust the system clock, or shut the system down, your tasks might be skipped. anacron [2] might be a better solution in some ways. Lastly, all implementations of cron that I am aware of don't have a great ability to make sure tasks actually run and finish, don't have retries built-in, and have a horrible interface for reporting errors (any output of the script is emailed to root@localhost from root@localhost).
Based on the above, you might think I am saying to never use cron. That's not at all true. Cron is extremely useful as a systems tool. If you package your software in the distro's package format (you should at least give this a try to see how the system is put together), cron is pretty much your only safe choice. Also, as long as you follow the rules cron sets up, and know of its potential issues, cron will be the workhorse that gets things done. Tasks like log rotation, periodic sanity checks, etc. are great for this. If you are writing a web application and are already using Python though, look at more sophisticated options such as Celery before using cron directly.
[1] http://manpages.ubuntu.com/manpages/maverick/en/man8/cron.8.... and https://bugs.launchpad.net/ubuntu/+source/cron/+bug/706565
I don't see any use case for Plan, it's just complicating an easy task.
I can't see the point of it at all.
When I want to kick off celery tasks I just have a cron job execute a django shell command.
A full megabyte on my machine, actually! Still a long way from 35MBs, though.
I use it extensively myself for scraping various sites/APIs.