Example work queue that extends WorkQueueBase
The following Gosu code is an example of a
simple custom work queue. It uses the StandardWorkItem
entity type for its work queue table. Its unit of work is an activity
that no one has viewed for five days or more. The process simply sends
an email to the user assigned to the activity. The process does not update
entity data, so the processWorkItemMethod
does not use the runWithNewBundle
API.
Note: In general, Guidewire recommends
that your custom work queue class extend
BulkInserWorkQueueBase rather
than WorkQueueBase. The
following example is for illustration only. uses gw.api.database.Query
uses gw.api.database.Relop
uses gw.api.email.EmailUtil
uses gw.processes.WorkQueueBase
uses java.util.Iterator
/**
* An example of batch processing implemented as a work queue that sends email
* to assignees of activities that have not been viewed for five days or more.
*/
class MyActivityEmailWorkQueue extends WorkQueueBase <Activity, StandardWorkItem> {
/**
* Let the base class register this type of custom process by
* passing the process type, the entity type the work queue item, and
* the target type for the units of work.
*/
construct() {
super ( BatchProcessType.TC_NOTIFYUNVIEWEDACTIVITIES, StandardWorkItem, Activity )
}
/**
* Select the units of work for a batch run: activities that have not been
* viewed for five days or more.
*/
override function findTargets() :Iterator <Activity> {
// Query the target type and apply conditions: activities not viewed for 5 days or more
var targetsQuery = Query.make(Activity)
targetsQuery.compare( Activity#LastViewedDate.PropertyInfo.Name, Relop.LessThanOrEquals,
java.util.Date.Today.addBusinessDays(-5) )
return targetsQuery.select().iterator()
}
/**
* Process a unit of work: an activity not viewed for five days or more
*/
override function processWorkItem(WorkItem: StandardWorkItem) {
// Extract an object referenct to the unit of work: an Activity instance
var activity = extractTarget(WorkItem) // Convert the ID of the target to an object reference
if (activity.AssignedByUser.Contact.EmailAddress1 != null) {
// Send an email to the user assigned to the activity
EmailUtil.sendEmailWithBody(null,
activity.AssignedUser.Contact, //To:
null, //From:
"Activity not viewed for five days", //Subject:
"See activity" + activity.Subject + ", due on " + activity.TargetDate + ".") //Body:
}
}
}
Notice that this work queue implementation uses a findTargets method to return an iterator of target objects on which to base the work items.
See also
