Thursday, October 24, 2013

WCS Schedulers


Introduction

Regular Scheduler Jobs: Any long running offline process can be run as a WCS scheduler job, think about them as regular WCS commands which gets triggered by WCS scheduler engine and performs a specific task based on your custom implementation, the jobs could be one time only or can be executed at a regular frequency.

Broadcast jobs: These are WCS jobs which run on every single WCS JVM in the cluster at least once,  Refresh Registry is one such job, this Job ensures registry which resides in WCS JVM on every instance is refreshed.

All WCS jobs require WCS runtime for there execution, which means they can not be run outside of WCS server or container.

In terms of datamodel, there are few key tables you need to be aware of
SCHCONFIG
SCHSTATUS
SCHACTIVE
SCHBRDCST

Creating a custom Scheduler Job

//Define the custom scheduler interface
package com.ibm.commerce.samples;
import com.ibm.commerce.command.ControllerCommand;
public interface MyCustomSchedulerCmd extends ControllerCommand {

public static final String defaultCommandClassName="com.ibm.commerce.samples.MyCustomSchedulerCmdImpl";

}

//Define the custom scheduler implementation class
package com.ibm.commerce.samples;
import java.util.logging.Logger;
import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.exception.ECException;

public class MyCustomSchedulerCmdImpl extends ControllerCommandImpl implements
        MyCustomSchedulerCmd {
   
    Logger logger = Logger.getLogger(MyCustomSchedulerCmdImpl.class.getName());

    public void performExecute() throws ECException {
        //implement custom logic
        logger.info("Hello World from custom scheduler");
    }
}

//Make following Struts Config entry

<action parameter="com.ibm.commerce.samples.MyCustomSchedulerCmd" path="/MyCustomScheduler" type="com.ibm.commerce.struts.BaseAction">
<set-property property="authenticate" value="0:0"/>
<set-property property="https" value="0:1"/>
</action>

//Make following DB entries to register the new JOB.

-- Use following queries for Apache Derby DB
insert into schconfig (sccjobrefnum,scchost,member_id,storeent_id,sccrecdelay,sccrecatt,sccpathinfo,sccquery, sccstart,sccinterval,sccpriority,sccsequence,sccactive,sccapptype,interfacename,optcounter) 
values 
((select Max(sccjobrefnum)+1 FROM schconfig),null, -1000,10051, 100,0,'MyCustomScheduler',null, CURRENT_TIMESTAMP, 100, 5,0,'A',default,'com.ibm.commerce.samples.MyCustomSchedulerCmd',0);

insert into schactive (scsinstrefnum,scsjobnbr,scsactlstart,scsattleft,scsend, scsinstrecov,scsprefstart,scsqueue,scsresult,scssequence,scsstate,scspriority,optcounter)
 values
 ((select Max(scsinstrefnum)+1 FROM schactive),(select max(sccjobrefnum) FROM schconfig), CURRENT_TIMESTAMP,1,null,null,CURRENT_TIMESTAMP,null,null,0,'I',default,0);

-- Oracle DB
insert into schconfig (sccjobrefnum,scchost,member_id,storeent_id,sccrecdelay,sccrecatt,sccpathinfo,sccquery, sccstart,sccinterval,sccpriority,sccsequence,sccactive,sccapptype,interfacename,optcounter)
 values 
((select Max(sccjobrefnum)+1 FROM schconfig),null, -1000,10051, 100,0,'MyCustomScheduler',null, CURRENT_TIMESTAMP, 100, 5,0,'A',default,'com.ibm.commerce.samples.MyCustomSchedulerCmd',0);

insert into schactive (scsinstrefnum,scsjobnbr,scsactlstart,scsattleft,scsend, scsinstrecov,scsprefstart,scsqueue,scsresult,scssequence,scsstate,scspriority,optcounter)
 values
 ((select Max(scsinstrefnum)+1 FROM schactive),(select max(sccjobrefnum) FROM schconfig), SYSDATE,1,null,null,CURRENT_TIMESTAMP,null,null,0,'I',default,0);

Sticky configuration for Scheduler jobs

A regular scheduler job by default may run randomly on any WCS instance in a cluster, you should use following configuration for sticky configuration of a Scheduler, this will allow it to run always from a given WCS instance in a cluster.

a. Define a JVM Property on the instance which will run the Scheduler Job
"com.ibm.commerce.scheduer.SchedulerHostName" and provide an identifier for the JVM that should run the job.

Refer following link for more details.
http://publib.boulder.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.admin.doc/tasks/tjsinstschjob.htm



b. While creating the Job replace the value for SCHCONFIG.SCCHOST with the value of the property, in this case as "mySchedulerJVM"

E.g. note that scchost has been replaced with 'mySchedulerJVM'


insert into schconfig (sccjobrefnum,scchost,member_id,storeent_id,sccrecdelay,sccrecatt,sccpathinfo,sccquery, sccstart,sccinterval,sccpriority,sccsequence,sccactive,sccapptype,interfacename,optcounter)
values
((select Max(sccjobrefnum)+1 FROM schconfig),'mySchedulerJVM', -1000,10051, 100,0,'MyCustomScheduler',null, CURRENT_TIMESTAMP, 100, 5,0,'A',default,'com.ibm.commerce.samples.MyCustomSchedulerCmd',0);



Monitoring and Maintaining Scheduler Jobs

WCS provides WAS Admin console from which you can validate the Job status, this tool essentially lists down every single job status from SCHSTATUS table and is not a very user friendly tool, for some reason the pagination and sorting feature does not work very well.
as an alternative option you can query OOB tables with your job name and validate the status of the job.

//This Query validates if you have the scheduler configured with the Active status
select sccjobrefnum from wcsadm.schconfig where sccpathinfo like '% MyCustomScheduler%' and sccactive='A'

select * from wcsadm.schactive where scsjobnbr IN
(select sccjobrefnum from wcsadm.schconfig where sccpathinfo like '% MyCustomScheduler%' and sccactive='A');

//This Query validates if an entry is created for the last run of Scheduler, if you don't see an entry here based on the job frequency of the scheduler it would mean the scheduler is not running successfully
select * from wcsadm.schstatus where scsjobnbr in (select sccjobrefnum from wcsadm.schconfig where sccpathinfo like '% MyCustomScheduler%' and sccactive='A')
order by scsactlstart desc;

Tuning WCS Schedulers

As of WCS 7, fix pack 2, we have few additional options to fine tune the scheduler jobs.
you can define a custom transaction timeout for scheduler Jobs which will be independent of your WAS level setting for global transaction timeout.

a. Disabling Scheduler in WCS instance
follow these steps If you have a need to not run any scheduler jobs from a given WCS instance,
Edit the wc-server.xml file of a given instance and edit the value enabled=false, this configuration will disable scheduler jobs from running on this instance.
 It is important to note that by doing this you are disabling the ability of this JVM to run any Broadcast event Jobs as well.

        <component
            compClassName="com.ibm.commerce.scheduler.SchedulerComm"
            enable="false" name="Scheduler">
            <property autoClean="off" broadcastExpireTime="1800"
                contextSetName="Authoring" cycleTime="600" display="false"/>
        </component>

b. Defining transaction timeout for Scheduler Jobs

Here are the steps which is part of APAR IZ02770, which explains how to specify the         
scheduler-specific transaction timeout settings:                       
                                                                        
Update the WC_installdir/instances/instanceName/xml/instanceName.xml
to include the new transactionTimeout field. Set the value in seconds  
for your desired transaction timeout for scheduled jobs                
                                                                       
<component                                                             
compClassName="com.ibm.commerce.scheduler.SchedulerComm"               
enable="true" name="Scheduler">                                         
<property autoClean="off"                                              
broadcastExpireTime="1800"                                             
transactionTimeout="1800"                                               
contextSetName="Authoring"                                             
cycleTime="600"                                                        
display="false">                                                       
</property>                                                             
</component>                                                           
                                                                       
Restart the application and test your scenario

2. Defining dedicated Container threads for Jobs
This setting might be useful if you are using WCS JVM to serve external traffic and also run some of the Scheduler jobs, the configuration defines maximum threads for various Jobs.

<component                                                             
compClassName="com.ibm.commerce.scheduler.SchedulerComm"               
enable="true" name="Scheduler">                                         
<property autoClean="off"                                              
broadcastExpireTime="1800"                                             
transactionTimeout="1800"                                              
contextSetName="Authoring"                                             
cycleTime="600"                                                        
display="false"> 
<applicationType applicationName="default" maxNumofThreads="10"/>      
<applicationType applicationName="broadcast" maxNumofThreads="10"/>    
<applicationType applicationName="auction" maxNumofThreads="10"/>      
<applicationType applicationName="inventory" maxNumofThreads="10"/>    
</property>                                                             
</component>

Refer following link for more details
http://publib.boulder.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.admin.doc/concepts/cjsconfig.htm
 
More Reading

Maintaining Scheduler
http://publib.boulder.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=/com.ibm.commerce.admin.doc/tasks/tjsmaint.htm

Websphere Commerce Scheduler Mustgather
https://www-304.ibm.com/support/docview.wss?uid=swg21454411

Use following trace component for troubleshooting and scheduler related issues.
*=info: enable.trace.log.*=all: com.ibm.websphere.commerce.WC_THREAD=all: com.ibm.websphere.commerce.WC_SERVER=all

Maintaining the WebSphere Commerce Scheduler tables
https://www-304.ibm.com/support/docview.wss?uid=swg21397348

No comments:

Post a Comment