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:
Method | Description |
---|---|
| Called when the The Note: Be aware that the defined interval specified in |
| Calls |
| Processes all scheduled This method calls |
| Uses the query defined in the |
| Processes the current scheduled This method calls If the scheduled |
| Sets the next time that the scheduled |
| This method checks out the current scheduled First, the template Second, the template Third, if the Fourth, the cloned Finally, the cloned |
| Reprices the cloned |
ATG Commerce provides an instance of class atg.b2bcommerce.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.
Configuring a Scheduled Order Service to Handle Large Orders
As described at the beginning of this section (see Scheduling Recurring Orders), the scheduled order service is designed to run on only one machine at a time, and for that reason it is not well adapted to handle very large orders. If you do need to use it in situations where the number of scheduled orders is very high, you can do so by configuring multiple servers so that each one processes a specific subset of orders, thus balancing the load. To achieve this behavior, modify the pollQuery
property of the ScheduledOrderService
component so that it limits the order query to a subset of the available orders. (The pollQuery
property is an instance of atg.repository.rql.RqlStatement
. For information on setting it, see the ATG Repository Guide.) For example, you could set up one server to add a clause to the query so that it handles only orders where the profiles’ last names begin with A-M. Then set up another server to handle only last names that begin with N-Z, thus splitting the load between the two servers.
In addition to changing the pollQuery
, you also need to change the lockName
property of the ScheduledOrderService
component so that it is unique for each server. Otherwise, if all the services use the same lockName
, only one instance will run at a time.