In Websphere Commerce we can configure two types of scheduler:
a. Regular Schedulers: Which are scheduled to run after a specific interval. Ex: Sync the inventory into database from an external system. Send orders to a external systems etc.
b. Broadcast Jobs: Which are run once on all instances in the cluster. Ex: Refresh registry on each instance.
Tables used for storing scheduler information:
SCHCONFIG: Stores the configuration of a scheduler, if the scheduler is a broadcast or a default, the frequency and the interval.
SCHACTIVE: Stores the status of the scheduled job and the time when the next scheduler will run.
SCHSTATUS: Stores the status of each run. (Only for regular schedulers)
SCHBRDCST: Stores the status of a job run in each instance (jvm) in a cluster. (Only for broadcast jobs)
Scheduler component can be enabled or disabled on a instance by setting the following component to true of false in wc-server.xml
com.ibm.commerce.scheduler.SchedulerComm
Scheduler can be configured using websphere commerce administration console. Using the tool will make an entry into SCHCONFIG and SCHACTIVE tables. We can also configure a scheduler by inserting into these tables using the insert SQL, SCHCONFIG for the details about the scheduler and type of scheduler, SCHACTIVE for the first run.
Each JVM instance runs the scheduler component, so this means any instance in the cluster can run the scheduled job. If the scheduler need to run only on a specific instance configure the SCCHOST of SCHCONFIG table with a specific value. Configure a JVM property with name as "com.ibm.commerce.scheduer.SchedulerHostName" and the value same as used in SCCHOST column of the SCHCONFIG table. This will make sure the scheduler is configured to run only on a single JVM.
How to configure a broadcast job to run at a specific intervals:
Step1- Configure a regular job to run at specific intervals of time and calls the command in step2.
Step2- Implement a command which reads the boolean property from request properties (if not available set as false). If the boolean property is false, configure a broadcast job who's name is same as the regular job(step1) and calls the same command(as in step1) by invoking AddBroadcastJobCmd with queryString property(request property) set to "booleanvariable=true".
If the boolean property is true implement the code to do the required functionality of the broadcast job.
This step creates a broadcast job with the column SCCQUERY of SCHACTIVE table set to a boolean property true. Now each JVM instance will read this broadcast job and execute on its JVM updating the SCHBRDCST table with the status that it has run on the JVM. There will be as many entries as the number of JVM's in the cluster.
How does Scheduler work
During the server startup, the SchedulerComm starts as a thread reading all scheduled jobs from SCHCONFIG table, this component is responsible for making sure the batch jobs are executed at configured time. It picks the configured job and adds and entry into SCHACTIVE table with time at which the scheduled job need to run. It then picks the entries from SCHACTIVE and executes the scheduled job.
No comments:
Post a Comment