Adding a new scheduled job
Adding a new scheduled job
To add a scheduled job to either the Commerce Manager server or Search server, do the following:
- Open the appropriate quartz.xml file:
- The Commerce Manager server quartz.xml file is located at cmserver\ep-cmserver\src\main\resources\spring\scheduling\quartz.xml
- The Search server quartz.xml file is located at search\ep-search\src\main\resources\spring\scheduling\quartz.xml
- In quartz.xml, define a job bean as shown below:
<bean id="newJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="newJobService"/commerce-legacy/> </property> <property name="targetMethod"> <value>executeMethod</value> </property> <property name="concurrent"> <value>false</value> </property> </bean>
- Replace the following values:
- newJob - the name of the bean.
- newJobService - the class that contains the logic for the scheduled job.
- executeMethod - the name of the method to execute in the class.
- concurrent - set to false to prevent jobs from executing concurrently.
- In quartz.xml, define a trigger bean as shown below:
<bean id="newJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="newJob"/commerce-legacy/> </property> <property name="cronExpression"> <value>0 0 0/1 * * ?</value> </property> </bean>
- Replace the following properties:
- newJob - the name of the job bean.
- cronExpression - the cron expression that sets how often the job should be executed. For more information on cron expressions, see the Quartz Cron Configuration
- Open the appropriate quartz-setup.xml file:
- The Commerce Manager server quartz-setup.xml file is located at cmserver\ep-cmserver\src\main\filtered-resources\spring\scheduling\quartz-setup.xml
- The Search server quartz-setup.xml file is located at search\ep-search\src\main\filtered-resources\spring\scheduling\quartz-setup.xml
- Add the new trigger to the list of triggers. For the Commerce Manager server, it will look similar to the code below:
<util:list id="schedulingTriggers"> <ref bean="cleanupOrderLocksTrigger"/commerce-legacy/> <ref bean="processImportJobTrigger"/commerce-legacy/> <ref bean="importJobCleanupTrigger"/commerce-legacy/> <ref bean="staleImportJobTrigger"/commerce-legacy/> <ref bean="cleanupSessionsTrigger"/commerce-legacy/> <ref bean="cleanupAbandonedCartsTrigger"/commerce-legacy/> <ref bean="cleanupFailedOrdersTrigger"/commerce-legacy/> <ref bean="cleanupFailedOrdersTrigger"/commerce-legacy/> <!-- add the reference to the new trigger here --> <ref bean="newJobTrigger" /> </util:list>