You are not logged in Log in Join
You are here: Home » Members » Lalo's page at Zope.org » Using cron with Zope

Log in
Name

Password

 

Using cron with Zope

One of the big difficulties people have with a "100% pure Zope" sollution is that Zope is, after all, user-driven. There is (apparently) no way of executing some task periodically, or in response to a mail message.

Well, these premises are not actually true. Yes, things only happen in Zope when someone makes a request (via HTTP, FTP, the Monitor, or whatever else someone happens to add in the future). However, it isn't really difficult to fulfill this simple requirement.

Let's assume you have a queue of comic strips; you want to allow the author to upload a new one anytime he wishes, but you want it to only go live by midnight (local time). In a static webserving world (and an Unix-like system, of course), you would store the queue somewhere, as physical files, and then use a cron job to move the oldest file in the queue to the static page everyday.

Well, the good news is that you can do exactly that with Zope.

Here are the steps you must follow:

  • first, of course, write the method you want to run periodically; make it a DTML Method, or a Python Method if it's more appropriated. Test it by running it manually (by entering the URL in your browser).

  • make sure your script returns an empty string on success. This is very important.

  • if you want to make sure this script won't run by accident, remove the "view" permission for Anonymous.

  • write your cron line like: "lynx -auth user:password -source http://somewhere.foo/path/to/script"

With this command, if the method is successful, cron will consider everything OK; if the method fails, Zope will return an error page, which lynx will dump, which cron will consider an error and mail back to you!

Security considerations

You don't want to have your Manager password in /etc/crontab or somewhere as visible as that - not to mention that it will appear to anyone who happens to type "ps ax" on the machine while the job is running. So, create a "cron" user as high as you can in the Zope hierarchy, then don't grant it any useful powers, except running these methods.

Other useful tools

There are other things you can use instead of lynx; for example, with wget: "wget -O - --http-user=username --http-password=password http://somewhere.foo/path/to/script". In this case, it is possible to save the password in a config file, and then use the standard filesystem security to keep it safe; consult the wget documentation about how to do that.

If you need anything more complex than running a simple script with no parameters, take a look at XML-RPC.