Skip to main content

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.


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.


1. Configure the ticker in the buildout (or zope.conf)


eggs =

zope-conf-additional =
      method /<your-plone-site>/@@cron-tick
      period 60
      user admin
      password admin_password

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.2 Optionally use memcached server(s) to share locks

You would use memcached if your Zope instance runs on multiple machines. In this case, all machines would run @@cron-tick at the same time, which is not what you want, especially when creating content. Memcached will share a lock between multiple machine, so only one machine will run the cron job.

A memcached server is a standalone server process which you can either get via your favourite package manager (for Debian / Ubuntu: apt-get install memcached)

Install and configure memcached, and add unimr.memcachedlock to buildout.cfg:

eggs =

You can specify where you are running your memcached servers in the MEMCACHEDLOCK_SERVERS environment variable, e.g.:

zope-conf-additional =
      MEMCACHEDLOCK_SERVERS <ip/hostname of host1>:<port>,<ip/hostname of host2>:<port>

The default port for memcached is 11211.

1.3 Optionally install memcached from buildout

You can also build memcached from a buildout:

parts +=

recipe = zc.recipe.cmmi
url =
extra_options = --with-libevent=${libevent:location}

recipe = ore.recipe.fs:mkfile
path = ${buildout:bin-directory}/memcached
mode = 0755
content =
    case "$1" in
       ${memcached:location}/bin/memcached -d -P $PIDFILE
        kill `cat $PIDFILE`
        $0 stop
        sleep 1
        $0 start
        echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
        exit 1

You need to have the libevent development libraries (apt-get install libevent-dev) or in buildout:

recipe = zc.recipe.cmmi
url =

Make sure that the (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.


* 11 * * portal/@@run_me
15,30 * * * python: portal.my_tool.runThis()

3. Wait and see

In the ZMI, go to the CronTool. If a cronjob has run the history is shown.


  • 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.


1.1.11 (2014-10-19)

  • Added z3c-slug and made sure that the CMF.Core permisssions are loaded in the zcml. Also added a gitignore. [benniboy]

1.1.10 (2012-10-08)

  • Make configlet work on context that implements IPloneSiteRoot [huub_bouma]

1.1.9 (2011-05-19)

  • Add to include docs in release. [WouterVH]

  • fixed bug in the isPending method: default parameter has to be inside the method or it will have the same value as when the instance was started so tasks will not be rerun as expected [svincic]

1.1.8 (2011-03-30)

  • Fix issue with string formatting for date in crontab utils by casting expected values to integers at first use. [davidjb]

1.1.7 (2011-03-25)

  • Convert all DateTime calls to use UTC. This fixes a bug when switching to daylight saving time. (thanks for bug report + fix to Michael Lindig)

  • Fix comparison bug in comma-separated cron syntax by first casting to an integer. (thanks for bug report + fix to David Breitkreutz)

1.1.6 (2010-10-19)

  • No longer support for the extened cron syntax with the /N and N-M formats This didn’t work as intended. The logic in the cron_utils is flawed i.c.w that syntax. That old code has been moved to a enumeration-support branch.

1.1.5rc1 (2010-07-30)

  • Add locales-directories [WouterVH]

  • Code-cleanup with pyflakes [WouterVH]

  • Removed, 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]


  • Patch by Derek Broughton which extends the cron syntax so that you can now also use /N and N-M formats


  • The egg with version 1.1.2 on egg servers (pypi is corrupt.

  • Fixed README, contained invalid rst


  • Fixed bug, missing ‘ConflictError’ import


  • share locks with memcached


  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (42.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page