Retrieving state/status for a Unit of Work
The retrieving state/status for a Unit Of Work (UOW) example shows how to retrieve the state or status for a UOW.
Previous examples illustrated how to find the Work object for a UOW based on the UOWID or date. When a UOW is submitted, you will have a WorkKey returned. This too can be used to fetch the Work. From the Work, you can determine its state and status. Putting this in a loop provides a simple polling mechanism to wait for a UOW to finish execution.
Note: If you are polling, you
need to retrieve the Work object each time you check the state.
ApiSession session;
WorkflowManager wMgr;
WorkKey workKey;
.
.
.
//it is assumed the session has been established
wMgr = session.workflowManager();
.
.
.
//it is assumed the work key been set
Work work = wMgr.getWork(workKey);
WorkState state = work.getState();
if (state.equals(WorkState.FINISHED) ||
state.equals(WorkState.CANCELLED) ||
state.equals(WorkState.EXPIRED)) {
//work is finished
String status = work.getExecutionStatus();
} else {
//work is not finished
}