Project

General

Profile

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 the PROCESS, CLASS or METHOD 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. Multiple jobs can be defined using the same subject ID if duplicate processes are required. The entry point configured for that process will be the program that is executed.
    • if the job's type is CLASS, this needs to be the fully-qualified name of a public, non-abstract, class, implementing the java.lang.Runnable interface and exposing a public constructor with no arguments. For a com.acme.SomeJobClass, its definition would look like:
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 the com.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 mandatory boolean flag, specifying if this job is enabled or not. Possible values are true or false.
  • mode is mandatory, and represents the scheduling mode for this job. The possible values are NOW, RECURRING and ONE-TIME, where:
    • NOW will execute the job immediately. This means that all jobs configured as NOW will be executed on server startup or immediately, right after they are added in the Admin Console. For launching occuring at server startup, the job will process after the rest of the server initialization including any initialization processing based on the InitTermListener server hooks.
    • ONE-TIME will execute the job only once, when the clock reaches the time represented by the cron expression.
    • RECURRING will execute the job an undefined number of times, depending on how the cron expression is setup.
  • The second, minute, hour, dayOfMonth, dayOfWeek, month and year 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 is RECURRING or ONE-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 (or in this saved version: quartz_job_scheduler_2.2.2_cronexpression_class_javadoc_20220217.pdf).

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="recurring"/>
       <node-attribute name="hour"    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-2022 Golden Code Development Corporation. ALL RIGHTS RESERVED.