SCHEDULER – The Introductory Overview
A WCS scheduler framework schedules and launch the jobs both at the site level and the store level. You can configure this job on a particular WebSphere Commerce instance or on a cluster member. Let’s checkout scheduler, a WCS defined job.
There are two ways to configure:
1) You can set up through Admin Console.
2) You can update scheduler information into the database through queries.
It has two types of jobs:
1) Scheduler Jobs:
Its an offline job executed by WCS scheduler engine at a defined point of time.
It will call a regular WCS commands to performs a specific task, based on your custom implementation.
Scheduled jobs can run one time only or at a regular intervals.
Example: Sync inventory into local DB from an external system.
Example: Sync orders to an external system.
2) Broadcast jobs:
Its a WCS jobs which run on every single WCS JVM in the cluster. Registry resides in WCS JVM and Refresh Registry is one of such job.
Example: Refresh Registry ensures Registry that every instance is refreshed.
SCHEDULER – The Technical Overview
Tables Involved In Scheduler Job:
1) SCHCONFIG
When you create a scheduler using WCS admin console, then all config details get stored in this table.
SCHCONFIG table column details:
SCCJOBREFNUM : Job reference number.
SCCHOST : The host name of the instance on which the scheduled job will be running.
MEMBER_ID : Owner of the scheduled job.
STOREENT_ID : (DEFAULT 0) The store ID of the store for which the scheduled job is running.
SCCRECDELAY : (DEFAULT 0) Delay in seconds between attempts.
SCCRECATT : (DEFAULT 0) Retry attempt count.
SCCPATHINFO : Custom command name.
SCCQUERY : Query string for the scheduled command.
SCCSTART : Scheduled start time for the job.
SCCINTERVAL : Job reschedule interval in seconds.
SCCPRIORITY : (DEFAULT 0) Priority.
SCCSEQUENCE : (DEFAULT 0) Job sequence number.
SCCACTIVE : (DEFAULT ‘A’) Job active indicator.
A – The scheduled job is active for the next run.
C – The scheduled job has completed successfully.
The job execution finish time get recorded in the SCSEND column of either the SCHSTATUS table or the SCHACTIVE table.
I – The scheduled job must run at the preferred start time, recorded in the SCSPREFSTART column of the SCHSTATUS or SCHACTIVE table.
N – The scheduled job is not configured.
SCCAPPTYPE : Application type.
INTERFACENAME : The interface of the check command which indicates whether the scheduled job needs to executed or not.
SCCDESCRIPTION : The column that describes the CustomJob command.
2) SCHACTIVE
This table has the info of which schedule job needs to run and at what specified time.
WCS scheduler framework looks up for this table to identify this.
SCHACTIVE table column details:
SCSINSTREFNUM : Instance number for this run.
SCSJOBNBR : It refers to a job reference number defined in the SCHCONFIG table.
SCSACTLSTART : The actual start time for this run of the job.
SCSATTLEFT : The number of retry attempts left.
SCSEND : End time for the job.
SCSINSTRECOV : If this is a retry of a failed job, this column refers to the instance of the failed job.
SCSPREFSTART : Preferred start time for this job.
SCSQUEUE : This column indicates what job queue this job is or was in.
The queue name is of the format hostName:cloneId:applicationType
SCSRESULT : Result of the job: failed or success.
SCSSEQUENCE : The scheduling policy for this job.
SCSSTATE : The state of the scheduled job.
SCSPRIORITY : (DEFAULT 5) The priority of the run of the job.
Valid values are 1 to 10 and the higher the priority, the sooner the job will run when the time has expired.
3) SCHSTATUS
This table holds the info of status of all scheduled jobs. Like what’s the current status of the schedule job, when it started, when it ended, whether it failed or succeed etc.
SCHSTATUS table column details:
SCSJOBNBR : It refers to a job reference number defined in the schconfig table.
SCSSTATE : state of the scheduled job.
SCSRESULT : result of job, success or fail.
Following are the value of SCSSTATE
W : the job is waiting for execution
I : the job is currently inactive.
IF : the job has run and failed.
R : the job is currently running.
RF : the job is running because of previous attempt failed.
C : the job is completed successfully.
CF : the job failed to execute successfully.
4) SCHERRORLOG
If specific scheduled job fails then the exception information get logged into SCHERRORLOG table
5) SCHORDERS
This table contains the entries for scheduled orders.
6) SCHCMD
This table contains the pathname. Its the same name which is defined in struts config path. Also its the same name which comes as drop down list of Scheduler name in Admin Console.
All the store and site level scheduler commands are configured in this table. For site level scheduler commands its not mandatory to configure in this table.
We can also use struts config file to configure site level scheduler controller commands. But for store level scheduler commands its mandatory to make entry in this table.
7) CHKCMD
This table contains information about check commands. It can be used by a store to determine whether scheduled job needs execution. Lets consider to run a specific scheduler command only on weekdays. So before running, it will be checked whether it’s weekday or not. This kind of validation is done through check command. All scheduler command may or may not have a check command.
8) CHKARRANG
This table associates the specified store command (SCHCMD) with the check command (CHKCMD).
SCHEDULER – The Procedural Overview
First we have to create a custom scheduler command and then after we will do the configuration part.
Creating Custom Scheduler Command:
1) Create a custom scheduler interface
package com.ibm.commerce.sample; import com.ibm.commerce.command.ControllerCommand; public interface MyCustomSchedulerCmd extends ControllerCommand { public static final String defaultCommandClassName="com.ibm.commerce.sample.MyCustomSchedulerCmdImpl"; }
2) Create a custom scheduler implementation class
package com.ibm.commerce.sample; 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("My custom scheduler"); } }
3) Make a struts config entry for custom command
<action path="/MyCustomScheduler" parameter="com.ibm.commerce.sample.MyCustomSchedulerCmd" type="com.ibm.commerce.struts.BaseAction"> <set-property property="authenticate" value="0:0"/> <set-property property="https" value="0:1"/> </action>
Scheduler Configuration Through DB Queries: [Method – 1]
We need to make a new DB entry in the below mentioned tables.
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,0, 0,0,'MyCustomScheduler',NULL, CURRENT_TIMESTAMP, 120, 1,0,'A',default,'com.ibm.commerce.sample.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);
Scheduler Configuration Through Admin Console: [Method – 2]
a) Login to Admin Console, and select site on the Admin Console site/store selection page.
b) Click Configuration and select Scheduler from drop down. It will show the list of jobs that are scheduled to run.
c) Click on button named New, present on right side panel. It will open New Scheduled Job Page for configuration
d) From the Job command list, select the job name for which you want to do configuration.
e) Complete the mentioned fields as per your need.
f) After completion, click OK. Your job will now get listed on the Scheduler Status Display page. It will run at the specified start time.
How To Delete A Scheduler:
Use an Admin Console to delete a scheduled job for your site.
a) Login to Admin Console, and select site on the Admin Console site/store selection page.
b) Click Configuration and select Scheduler from drop down. It will show the list of jobs that are scheduled to run.
c) Select the check box of the scheduled job which you want to delete.
d) Click on button named Delete, present on right side panel.
e) A warning message displays as popup and ask if you are sure to delete the selected job.
f) Click OK to confirm the deletion. The job get cleared from the Scheduler Status Display page and marked as deleted.
Regular Use Query:
1) Query to check the jobs which are in active status. SELECT * FROM SCHCONFIG WHERE SCCPATHINFO LIKE '%MyCustomScheduler%' AND SCCACTIVE='A';
2) Query to check the status of a scheduler job. SELECT * FROM SCHSTATUS WHERE SCSJOBNBR IN (SELECT SCSJOBNBR FROM SCHCONFIG WHERE SCCPATHINFO LIKE '%MyCustomScheduler%' AND SCCACTIVE='A') ORDER BY SCSPREFSTART DESC;
3) Query to check the status of a scheduler job within a time range. SELECT * FROM SCHSTATUS WHERE SCSJOBNBR IN (SELECT SCSJOBNBR FROM SCHCONFIG WHERE SCCPATHINFO LIKE '%MyCustomScheduler%' AND SCCACTIVE='A') AND SCSPREFSTART BETWEEN TO_TIMESTAMP('02.01.14 08:00:00.000000','MM.DD.YY HH24:MI:SS:FF') AND TO_TIMESTAMP('02.01.14 09:00:00.000000','MM.DD.YY HH24:MI:SS:FF') ORDER BY SCSPREFSTART DESC;
SCHEDULER – The Summary
In short, scheduler command and task command details get stored in SCHCMD and CHKCMD table respectively. Scheduler configuration related details get stored in SCHCONFIG and SCHACTIVE.
Scheduler framework monitors the SCHACTIVE table to identify which scheduled job needs to run at a specified time.
Framework pulls the corresponding scheduled job configuration details from SCHCONFIG table and executes the identified scheduled job.
It update the status in SCHSTATUS table. If specific scheduled job fails then the exception information get logged into SCHERRORLOG table.
Sung Philmore
Thank you for your post. I really enjoyed reading it, especially because it addressed my issue. It helped me a lot and I hope it will help others too.
Piedad Halik
Thank you for sharing this article with me. It helped me a lot and I love it.
Caitlin
Greetings from Florida! I’m bored to death at work so I decided to check out your website on my iPhone during lunch break. I really like the knowledge you present here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my cell phone. I’m not even using WIFI, just 3G… Anyways, wonderful site!
Jacquenetta Marmaduke Joslyn
I like the valuable information you provide in your articles. I will bookmark your blog and take a look at once more here regularly. I am reasonably certain I will learn many new stuff proper right here! Good luck for the following!
Neysa Jefferey Blakele
Pretty! This has been a really wonderful post. Thanks for providing this information.
Myrlene Cassie Tankoos
I really liked this piece of content and I will return to view more of your lovely stuff. Thank you so much!
Jessie Mead Khai
Rattling nice design and style and good subject matter, practically nothing else we want.
Vanni Wolfie Kernan
Hello. This post was really remarkable, especially because I was looking for thoughts on this issue last Tuesday.
Estel Murdock Smitt
Wonderful, what a weblog it is! This web site presents useful data to us, keep it up.
Mellicent Boot Steffi
This piece of writing gives clear idea in support of the new people of blogging, that truly how to do running a blog.
Meghann Van Linis
Super-Duper blog! I am loving it!! Will be back later to read some more. I am taking your feeds also.
Katie Kirk Zach
Hey there. I discovered your site by the use of Google while searching for a similar subject, your website got here up. It seems to be great. I have bookmarked it in my google bookmarks to come back then.
Milli Scotty Kaye
Just wish to say your article is as astounding. The clarity in your submit is just cool and I could assume you are a professional on this subject. Fine with your permission allow me to grasp your feed to stay up to date with coming near near post. Thank you a million and please keep up the rewarding work.
Lise Delmer Zendah
Hi there. I discovered your site by the use of Google even as looking for a similar subject, your web site got here up. It appears to be great. I have bookmarked it in my google bookmarks to visit then.
Alta Jabez Idaline
After exploring a few of the articles on your web site, I truly like your technique of writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the near future. Please check out my web site too and let me know how you feel.
Kimbra Roland Tierza
Way cool! Some very valid points! I appreciate you penning this post and the rest of the website is very good.
Mira Stan Batchelor
I think other web-site proprietors should take this website as an model, very clean and fantastic user genial style and design, let alone the content. You are an expert in this topic!
Cynthie Rafaello Gratiana
Thanks a lot for the article post. Really thank you! Great.
Darci Westbrook Lavona
I am truly happy to glance at this web site posts which carries tons of useful data, thanks for providing such statistics.
Dody Boony Frodeen
Good post! We will be linking to this particularly great post on our website. Keep up the good writing.
Abhijit Chatterjee
Superb… readable and correct conceptual representation. Please keep updating more topics.