Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Adding a new scheduled job

Adding a new scheduled job

To add a scheduled job to either the Batch Server or Search server, do the following:

  1. Open the appropriate quartz.xml file:
    • The Batch server quartz.xml file is located at batch\ep-batch\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
  2. 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>
    
  3. 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.
  4. 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>
    
  5. 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
  6. Open the appropriate quartz-setup.xml file:
    • The Batch Server quartz-setup.xml file is located at batch\ep-batch\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
  7. Add the new trigger to the list of triggers. For the Batch 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>