Scheduling Tasks¶
In FWD, it is possible to schedule processes or arbitrary Java code to be executed at a certain time or interval. For recurring or time-specific tasks, the scheduler accepts a cron-style expression, which has the same syntax as the expressions used for scheduling jobs with cron tools in unix-like operating systems. The scheduler sub-system relies on the Quartz libraries, but only for parsing the cron expressions.
Configuration¶
The scheduler can be configured per-server or as the default configuration, in a /server/<server-id>/scheduler/
or /server/default/scheduler/
node. This node will have as children one or more job
nodes, each one having as class the job
class, as defined in the directory schema:
<object-class name="job" leaf="true" immutable="false"> <class-attribute name="type" type="STRING" mandatory="true" multiple="false" immutable="false" /> <class-attribute name="target" type="STRING" mandatory="true" multiple="false" immutable="false" /> <class-attribute name="enabled" type="BOOLEAN" mandatory="true" multiple="false" immutable="false" /> <class-attribute name="mode" type="STRING" mandatory="true" multiple="false" immutable="false" /> <class-attribute name="second" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="minute" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="hour" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="day-of-week" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="day-of-month" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="month" type="STRING" mandatory="false" multiple="false" immutable="false" /> <class-attribute name="year" type="STRING" mandatory="false" multiple="false" immutable="false" /> </object-class>
where:
type
is mandatory and represents the job's type, which is one of thePROCESS
,CLASS
orMETHOD
strings.target
is mandatory and represents the job's target, depending on its type:- if the job's type is
PROCESS
, this needs to be a valid subject ID for a process account. - if the job's type is
CLASS
, this needs to be the fully-qualified name of a public, non-abstract, class, implementing thejava.lang.Runnable
interface and exposing a public constructor with no arguments. For acom.acme.SomeJobClass
, its definition would look like:
- if the job's type is
package com.acme; public class SomeJobClass implements Runnable { public SomeJobClass() { /* initialization code goes here */ } public void run() { /* job's body goes here */ } }
- If the job's type is
METHOD
, this needs to be the name of a fully-qualified public class followed by a dot and the name of a no-argument method. The method can be either a static or an instance method. If the method is an instance method, then the class must be a non-abstract class defining a public constructor with no arguments. If using thecom.acme.SomeClass.jobMethod
string to refer a static method, then the definition of this method can look like:
package com.acme; public class SomeClass { public static void jobMethod() { /* job's body goes here */ } }
package com.acme; public class SomeJobClass implements Runnable { public SomeJobClass() { /* initialization code goes here */ } public void jobMethod() { /* job's body goes here */ } }
enabled
is a mandatoryboolean
flag, specifying if this job is enabled or not. Possible values aretrue
orfalse
.mode
is mandatory, and represents the scheduling mode for this job. The possible values areNOW
,RECURRENT
andONE-TIME
, where:NOW
will execute the job immediately. This means that all jobs configured asNOW
will be executed on server startup or immediately, right after they are added in the Admin Console.ONE-TIME
will execute the job only once, when the clock reaches the time represented by the cron expression.RECURRENT
will execute the job an undefined number of times, depending on how the cron expression is setup.
- The
second
,minute
,hour
,dayOfMonth
,dayOfWeek
,month
andyear
fields represent the cron entries defining when and how many times to execute the job. These fields need to be specified only if the job's mode isRECURRENT
orONE-TIME
; when a field is missing, its value defaults to *. To determine the next execution time, FWD uses the cron expression parser provided by the Quartz library. Each field's syntax must follow the documentation provided by the@ org.quartz.CronExpression class javadoc, which can be found here: http://quartz-scheduler.org/api/2.0.0/org/quartz/CronExpression.html
Considering the job configuration, following is an example which configures a job to be executed at server startup, to automatically start the agents associated with an appserver:
<node class="container" name="scheduler"> <node class="job" name="start_appserver"> <node-attribute name="type" value="process"/> <node-attribute name="target" value="PROCESS_NAME_GOES_HERE"/> <node-attribute name="enabled" value="TRUE"/> <node-attribute name="mode" value="now"/> </node> </node> </node>
and next is an example which shows how to configure a Java class to be executed each day at 8PM (as previously noted, the missing cron fields all default to the * value):
<node class="container" name="scheduler"> <node class="job" name="daily_job"> <node-attribute name="type" value="class"/> <node-attribute name="target" value="com.acme.SomeJobClass"/> <node-attribute name="enabled" value="TRUE"/> <node-attribute name="mode" value="recurrent"/> <node-attribute name="hours" value="20"/> </node> </node>
Search Algorithm¶
The scheduler is first searched in the per-server configuration, in a /server/<server-id>/scheduler/
node. If not found, the default configuration from /server/default/scheduler/
node is used.
© 2004-2017 Golden Code Development Corporation. ALL RIGHTS RESERVED.