Managing failed work items

If your custom worker code encounters an error while operating on a target instance, throw an exception. PolicyCenter detects and throws some types of exceptions automatically, such as a concurrent data change exception (CDCE). These types of exceptions generally resolve themselves quickly and automatically. However, it is also possible that your code detects other logic errors that require human intervention to resolve. If so, implement a custom exception and throw it whenever your worker code detects the exceptional situation.

PolicyCenter catches exceptions thrown by code within the scope of your custom processWorkItem method. Whenever PolicyCenter catches an exception, it increments the Attempts property on the work item. If the value of the Attempts property does not exceed the value of the WorkItemRetryLimit parameter set in config.xml, PolicyCenter sets the Status property of the work item to available. Otherwise, PolicyCenter sets the Status property of the work item to failed.

Retrying work items that cause exceptions

PolicyCenter makes work items that trigger exceptions available again on the work queue, because many exceptions resolve themselves quickly. For example, a CDCE exception often occurs whenever two worker tasks attempt to update common data related to their two separate units of work. By the time PolicyCenter gives a work item that encountered an exception to another worker task, the exceptional condition often resolves itself. The second worker then process the work item to completion successfully.

Handling exceptions

In your custom work queue class, provide an implementation of the handleException method inherited from WorkQueueBase to augment the actions taken whenever code in the processWorkItem method throws an exception. For example, it is possible for your worker code to throw an exception whenever it encounters a logic error that cannot resolve itself without human intervention.