The ScheduledOrderService is the back-end service that polls the Order Repository at a periodic interval and submits scheduled Orders according to their schedules.

When an application that includes ATG Commerce deploys, a PlaceScheduledOrders task is scheduled with the /atg/dynamo/service/Scheduler. This scheduled task is run at the interval specified in ScheduledOrderService.schedule. When the scheduled task is run, the Scheduler calls ScheduledOrderService.performScheduledTask(). The ScheduledOrderService then attempts to obtain a global write lock from the server lock manager. If the lock is obtained successfully, then it calls doScheduledTask().

At a general level, the ScheduledOrderService.doScheduledTask() method polls the Order Repository for all scheduled Orders that should be checked out. For each scheduled Order it finds due for checkout, it then clones the template Order associated with the scheduled Order, checks out the cloned Order, and sets the nextScheduledRun property of the scheduled Order to the next date and time it should be checked out. If an error occurs when processing an individual scheduled Order, then a CommerceException is thrown, the state of the scheduled Order is set to Error, and the state of the cloned Order is set to PENDING_MERCHANT_ACTION. However, the remaining scheduled Orders are processed.

The following table describes the various methods of ScheduledOrderService that support this process:




Called when the Scheduler finds that the placeScheduledOrders task is scheduled to run. When this method is called, the ScheduledOrderService attempts to obtain a global write lock from the server lock manager. If the lock is obtained successfully, the ScheduledOrderService calls its own doScheduledTask() method.

The placeScheduledOrders task is run at the interval defined in ScheduledOrderService.schedule. While the schedule that you set depends on the business needs of your site, as a general rule, it is recommended that you set it to “every 1 day.” For information on how to specify a schedule, see the Scheduler Services section of the Core Dynamo Services chapter in the ATG Programming Guide.

Note: Be aware that the defined interval specified in ScheduledOrderService.schedule begins when an application that includes ATG Commerce deploys. Therefore, if, for example, the ATG Commerce server is redeployed every 11 hours, and if the schedule property of a given scheduled Order is set to “every 12 hours,” then the scheduled Order is never placed.


Calls processDueScheduledOrders() to process any scheduled Orders that need to be checked out. Other objects can call this method to trigger on demand a poll of the Order Repository for due scheduled Orders.


Processes all scheduled Orders that need to be checked out.

This method calls pollForNewOrders() to retrieve the list of scheduled Orders that need to be checked out. It then iterates through the array and calls processDueScheduledOrder() on each scheduled Order. (See the methods described later in this table for details.)


Uses the query defined in the ScheduledOrderService.pollQuery property to poll the Order Repository defined in the ScheduledOrderService.orderRepository property with the repository view defined in the itemDescriptorName property (by default, set to scheduledOrder). The method returns an array of scheduled Orders that need to be checked out.


Processes the current scheduled Order.

This method calls placeScheduledOrder() to check out the scheduled Order. If the scheduled Order is successfully checked out, then the method calls getNextScheduledRun() to set its nextScheduledRun property to the next date and time that it should be checked out.

If the scheduled Order fails to be checked out, then it rolls back to its original state. It will be retrieved again for processing the next time that pollForNewOrders() is executed.


Sets the next time that the scheduled Order should be checked out.


This method checks out the current scheduled Order using the following process:

First, the template Order is retrieved by calling ScheduledOrderTools.getTemplateOrder() and passing in the current scheduled Order.

Second, ScheduledOrderTools.UseOrderPriceListsFirst identifies if price list information should be extracted from an order template. The default is false.

Third, the template Order is cloned by calling ScheduledOrderTools.cloneOrder().

Fourth, if the ScheduledOrderTools.repriceOnClone property is set to True, then the cloned order is repriced by calling ScheduledOrderTools.repriceScheduledOrder().

Fifth, the cloned Order is saved to the Order Repository in its present state by calling OrderManager.updateOrder(), which executes the updateOrder pipeline. (For more information on the updateOrder pipeline, see Updating an Order with the OrderManager in this chapter.)

Finally, the cloned Order is checked out by calling ScheduledOrderTools.processScheduledOrder(), which in turn calls OrderManager.processOrder() and passes in the cloned Order and pipeline to execute. The pipeline to execute is set in ScheduledOrderTools.processOrderChainId; by default, this property is set to processOrder. When the order has been checked out successfully, it is passed on to Fulfillment. (For more information on the processOrder pipeline, see Checking Out an Order in this chapter.)


Reprices the cloned Order. The repriceScheduledOrder() method calls ScheduledOrderTools.repriceScheduledOrder(), which executes the repricing pipeline specified in ScheduledOrderTools.repriceOrderChainId. By default, this property is set to repriceOrder. (For more information on the repriceOrder pipeline, see the Commerce Processor Chains section.)

ATG Commerce provides an instance of class atg.commerce.order.scheduled.ScheduledOrderService, which extends atg.service.scheduler.SingletonSchedulableService. It is located in Nucleus at /atg/commerce/order/scheduled/ScheduledOrderService.

Class atg.service.scheduler.SingletonSchedulableService enables multiple ATG Commerce servers to run the same scheduled service, while guaranteeing that only one instance of the service will perform the scheduled task at any given time. This provides a degree of protection from server failures, since the loss of any single ATG Commerce server will not prevent the scheduled service from running on some other ATG Commerce server.

To use a SingletonSchedulableService like ScheduledOrderService on multiple ATG Commerce instances, you must run a server lock manager and point all client lock managers at it. For more information on SingletonSchedulableService, see the Scheduler Services section of the Core Dynamo Services chapter in the ATG Programming Guide.

loading table of contents...