Helma Logo
main list history

Cronjobs

Helma 1 provides a cronjob feature for running periodic tasks. In addition to cron jobs defined in code through app.addCronJob() it is also possible to define cron jobs in app.properties. All settings are prefixed with "cron.<jobname>".

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 schedulerInterval property in app.properties 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

Links to this page: Server and Application Properties