Helma Logo
main list history

Version 3 by hannes on 19. February 2009, 12:14

Version 2 by hannes on 17. February 2009, 23:10

48Seconds 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 *schedulerInterval property in app.properties</a> properties|server and application 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* 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.

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

1Helma 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;".
3=== Function
4
5First you define which javascript function is called, this can be a global function:
6
7 cron.testjob.function = someGlobalFunction
8
9or this can be a function on any object with a path similar to the xmlrpc calls, only that the string must start with "root".
10
11 cron.testjob.function = root.someObject.someFunction
12
13=== Interval
14
15Second, 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.
16
17 cron.testjob.year = <year-list>
18
19A list of years, ranges can be used e.g.
202002,2003,2005
212000-2003,2005-2007,2009-2011
22
23 cron.testjob.month = <month-list>
24
25A list of month names, no ranges e.g.
26january,february
27
28 cron.testjob.day = <day-list>
29
30A list of day-of-months values, ranges can be used, e.g.:
311,15
321-7,10-20
33
34 cron.testjob.weekday = <weekday-list>
35
36A list of weekday names, e.g.:
37monday,tuesday,friday
38
39 cron.testjob.hour = <hour-list>
40
41A list of hours, e.g.:
420,1,8-17
43
44cron.testjob.minute = <minute-list>
45A list of minutes, e.g.:
460,5,10,15,20,25,30
47
48Seconds 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.
49
50Examples:
51
52 # has been executed on the first day of y2k once:
53 cron.fireworks.year = 2000
54 cron.fireworks.month = january
55 cron.fireworks.day = 1
56 cron.fireworks.hour = 3
57 cron.fireworks.minute = 0
58     
59 # has been executed on the first day of y2k once  every minute
60 # between 3 and 4 o'clock (note the missing minute specification)
61 cron.fireworks.year = 2000
62 cron.fireworks.month = january
63 cron.fireworks.day = 1
64 cron.fireworks.hour = 3
65     
66 # on weekends early in the morning:
67 cron.job1.weekday = saturday, sunday
68 cron.job1.hour = 5
69 cron.job1.minute = 0
70     
71 # every five minutes:
72 cron.job2.minute = 0,5,10,15,20,25,30,35,40,45,50,55
73     
74 # this function will be executed every minute, as all interval
75 # settings are on *
76 cron.scheduler.function = scheduler
77 
78=== Timeout
79
80The default timeout is 60 seconds, which can be changed by specifying a timeout property:
81
82 cron.job1.timeout = timeout-in-seconds
83
84<!-- 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.
85
86So 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. -->