Helma Logo
main list history
previous version  overview  next version

Version 1 by hannes on 17. February 2009, 22:01

Helma 1 provides a cronjob feature for running periodic tasks. In addition to cron jobs defined in code through <a href="http://helma.zumbrunn.net/reference/app.html#app.addCronJob">app.addCronJob()</a> it is also possible to define cron jobs in app.properties. All settings are prefixed with "cron.&lt;jobname&gt;".

=== Function

First you define which javascript function is called, this can be a global function:

cron.testjob.function = someGlobalFunction

or this can be a function on any object with a path similar to the xmlrpc calls, only that the string must start with "root".

cron.testjob.function = root.someObject.someFunction

=== Interval

Second, you define the intervals. An asterisk (*) means that this part is not going to be used for determining if a cronjob fits the current time. As this is the default, you can drop those lines. Lists are comma-separated (,), sometimes ranges (X-Y) can be used.

cron.testjob.year = <year-list>

A list of years, ranges can be used e.g.
2002,2003,2005
2000-2003,2005-2007,2009-2011

cron.testjob.month = <month-list>

A list of month names, no ranges e.g.
january,february

cron.testjob.day = <day-list>

A list of day-of-months values, ranges can be used, e.g.:
1,15
1-7,10-20

cron.testjob.weekday = <weekday-list>

A list of weekday names, e.g.:
monday,tuesday,friday

cron.testjob.hour = <hour-list>

A list of hours, e.g.:
0,1,8-17

cron.testjob.minute = <minute-list>
A list of minutes, e.g.:
0,5,10,15,20,25,30

Seconds and milliseconds are ignored, so the smallest interval is a minute. For cases where you need to run cron jobs every few seconds, the <a href="http://helma.org/docs/guide/properties/listall/">schedulerInterval property in app.properties</a> can serve as a workaround. It specifies the time in seconds after which scheduled cron jobs are executed again. While that makes it possible to cause cron jobs to be run several times per minute, it will have the side effect to invoke *all* cronjobs at the specified seconds interval within the minute that they are scheduled to run. For example, with schedulerInterval set to 5, a cron job that is scheduled to run once a week, will run every five seconds during one minute once a week.

Examples:

# has been executed on the first day of y2k once:
cron.fireworks.year = 2000
cron.fireworks.month = january
cron.fireworks.day = 1
cron.fireworks.hour = 3
cron.fireworks.minute = 0
     
# has been executed on the first day of y2k once  every minute
# between 3 and 4 o'clock (note the missing minute specification)
cron.fireworks.year = 2000
cron.fireworks.month = january
cron.fireworks.day = 1
cron.fireworks.hour = 3
     
# on weekends early in the morning:
cron.job1.weekday = saturday, sunday
cron.job1.hour = 5
cron.job1.minute = 0
     
# every five minutes:
cron.job2.minute = 0,5,10,15,20,25,30,35,40,45,50,55
     
# this function will be executed every minute, as all interval
# settings are on *
cron.scheduler.function = scheduler
 
=== Timeout

The default timeout is 60 seconds, which can be changed by specifying a timeout property:

cron.job1.timeout = timeout-in-seconds

<!-- All this poses an internal problem: Until now only the interval between two calls of the scheduler could be specified, the duration of the call wasn't taken into account. As the execution (of several jobs or a job with a high timeout) might take longer than a minute jobs that are scheduled a minute later could be missed. Fire-and-forget on the other hand might bring down a slow application.

So the internal thread model should be changed a bit: The application thread first cleans up the sessions, calls the cron jobs for the current point of time, assigns each job an evaluator and stores them. The evaluators are either taken from the web accessible evaluators or from a special cron thread pool. The application thread then sleeps until the next full minute. After clean up new jobs are only executed if the matching job from the last call has already been finished. -->

     removed
     added