About custom work queue classes

You implement the code for your writer and your workers as methods on a single Gosu class. You must derive you custom work queue class from the WorkQueueBase class. This base class and the work queue framework provide most of the logic for managing the work items in your work queue. You typically need override only few methods in the base class to implement the code for your writer and your workers.

Work queue writer

You implement the writer for your work queue by overriding the findTargets method inherited from the base class. Your code selects the units of work for a batch and returns an iterator for the result set. The work queue framework then uses the iterator to create and insert work items into your work queue. Each work items holds the instance ID of a unit of work in your result set.

For example, your custom work queue sends email about overdue activities to their assignees. In this example, instances of the Activity entity type are the units of work for the work queue. In your findTargets methods, you query the database for activity instances in which the last viewed date of an open activities exceeds 30 days. You return an iterator to the result set, and then the framework creates a work item for each element in the result.

Work queue workers

You implement the workers of your work queue by overriding the processWorkItem method inherited from the base class. The work queue framework calls the method with a work item as the sole parameter. Your code accesses the unit of work identified in the work item and processes it to completion. Upon completion, your code returns from the method, and the work queue framework deletes the work item from the work queue.

For example, the units of work for your work queue are open activities that have not been viewed in the past 30 days. In your processWorkItem method, you access the activity instance identified by the work item. Then, you generate and send an email message to the assignee of that activity. After your code sends the email, it returns from the method. The framework then deletes the work item and updates the count of successfully processed work items in the process history for the batch.