cron4plone can do scheduled tasks in Plone
Project description
Product description
Cron4Plone can do scheduled tasks in Plone, in a syntax very like *NIX systems’ cron daemon. It plugs into Zope’s ClockServer machinery.
Optionally cron4plone also uses unimr.memcachedlock to make sure that only one task is running at a time, even when using a distributed environment like multiple zeo clients on multiple machines.
Rationale
Cron4plone uses the clockserver and allows advanced task scheduling:
Scheduled tasks at scheduled times. E.g. I want to perform a certain task at 3 AM on the first day of the month.
Single thread running the task: We don’t want 2 threads running the same task at the same time. When using clock server only this might happen if a task takes longer than the tick period.
Installation
1. Configure the ticker in the buildout (or zope.conf)
buildout.cfg:
[instance] ... eggs = Products.cron4plone zope-conf-additional = <clock-server> method /<your-plone-site>/@@cron-tick period 60 user admin password admin_password </clock-server>
The user and password variables can be omitted, but are required if you want to call a view that requires special permissions, for example when trying to create content.
1.1 Multiple instances
If you have multiple Zope instances in your buildout, it makes sense to add the zope-conf-additional to one instance only. This will ensure only one instance will try to run the @@cron-tick method.
Products.cron4plone should be present in all instances, or else the instance won’t have the software for CronTool object. This will cause errors on startup and you won’t be able to change the cron jobs.
1.3 Optionally install memcached from buildout
You can also build memcached from a buildout:
parts += memcached memcached-ctl supervisor [memcached] recipe = zc.recipe.cmmi url = http://memcached.googlecode.com/files/memcached-1.4.0.tar.gz extra_options = --with-libevent=${libevent:location} [memcached-ctl] recipe = ore.recipe.fs:mkfile path = ${buildout:bin-directory}/memcached mode = 0755 content = #!/bin/sh PIDFILE=${memcached:location}/memcached.pid case "$1" in start) ${memcached:location}/bin/memcached -d -P $PIDFILE ;; stop) kill `cat $PIDFILE` ;; restart|force-reload) $0 stop sleep 1 $0 start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 1 ;; esac
You need to have the libevent development libraries (apt-get install libevent-dev) or in buildout:
[libevent] recipe = zc.recipe.cmmi url = http://www.monkey.org/~provos/libevent-1.3b.tar.gz
Make sure that the libevent.so (shared object) file is in your LD_LIBRARY_PATH before you start the memcached server if you build the libevent library from the buildout.
If you use supervisor, you can add a line like this to start the memcached server:
10 memcached ${buildout:directory}/parts/memcached/bin/memcached
2. Configure the scheduled tasks
In the Plone site setup, go to the cron4plone configuration. This form can be used to enter cron-like jobs.
The cron job should have 5 elements: minute, hour, day_of_month, month and command expression. For command, a TAL expression can be used (including ‘python: ‘). The variable portal is the Plone site root.
Examples:
* 11 * * portal/@@run_me 15,30 * * * python: portal.my_tool.runThis()
Since the 1.1.4 release the /N and N-M syntax is also supported, thanks to Derek Broughton. This example will run the cron job
*/4 11 * * portal/@@run_me
3. Wait and see
In the ZMI, go to the CronTool. If a cronjob has run the history is shown.
TODO
Day of week is missing in cron-like syntax, add it.
Send mail report each time a job run, or only when one fail.
Improve doc test, currently test has basic coverage.
Perhaps make a configuration form that allows users without cron syntax knowledge to enter jobs.
License and credits
Authors: Huub Bouma and Kim Chee Leong
License: This product is licensed under the GNU Public License version 2. See the file docs/LICENSE.txt included in this product.
Parts of the code were taken from plonemaintenance by Ingeniweb.
Changelog
1.1.5rc1 (2010-07-30)
Add locales-directories [WouterVH]
Code-cleanup with pyflakes [WouterVH]
Removed tests.py-module, since we already have a tests-directory [WouterVH]
Removed setup.cfg to have full control over name of released egg [WouterVH, khink]
Extended and re-formatted documentation [khink]
1.1.4
patch by Derek Broughton which extends the cron syntax so that you can now also use /N and N-M formats
1.1.3
The egg with version 1.1.2 on egg servers (pypi plone.org) is corrupt.
Fixed README, contained invalid rst
1.1.2
Fixed bug, missing ‘ConflictError’ import
1.1.1
share locks with memcached
1.0
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for Products.cron4plone-1.1.5rc1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8e2e900d77a4a58a5edce7e4c559304d38b6e1d98f0ae7b5ffcaa2d733dc958 |
|
MD5 | f249f726c3591d0216a22b42fdbd21ba |
|
BLAKE2b-256 | 20576be02b2f01540fd308153e25d36bc12babc8087694323c9e9be8f7ec5a52 |