Tuesday, October 4, 2011

Human Workflow - with multiple callbacks

In one of my discussions with a customer, there was a query regarding the Human workflow and the flow of control between different activities. They wanted to know how the BPEL service and Workflow service interacts with each other. If you see the InitiateTask operation it is a synchronous operation which calls the workflow service and passes the payload and task attributes and gets the control back to BPEL process.
In case of a basic flow the initiate task is executed, workflow service instance is created and service waits in queue of user to be approved/rejected or complete an outcome. Where as in BPEL the control returns after initiateTask invocation, but the next activity is a receive callback from Workflow service which will only trigger once the user completes his action. So the BPEL process instance gets dehydrated and waits for action.
In case of designing an advanced flow with multiple callbacks, the BPEL generates extra code to handle multiple operation updates that happen from the workflow service. The workflow service will run as an independent process flow which has java API calls to invoke the callback operations defined in the TaskService wsdl  to give back control to BPEL after different task stages. In BPEL, the flow goes into a while loop waiting for a callback from the workflow service. The Pick activity as shown below will be looking for onMessage from ->OnTaskCompleted,OnTaskAssigned,OnTaskUpdated and OnSubTaskUpdated.
  • onTaskCompleted — This callback is invoked when the task is completed, expired, withdrawn, or errored.
  • onTaskAssigned — This callback is invoked when the task is assigned to a new set of assignees due to the following actions:
    • Outcome update
    • Skip current assignment
    • Override routing slip
  • onTaskUpdated — This callback is invoked for any other update to the task that does not fall in the onTaskComplete or onTaskAssigned callback. This includes updates on tasks due to request for information, submit information, escalation, reassign, and so on.
  • onSubTaskUpdated — This callback is invoked for any update to a subtask.
 To go to advanced mode, select the Allow task and routing customizations in BPEL callbacks check box. This  will enable the workflow service to  notify the BPEL process using OnMessage callbacks every time a task is routed to a different user or when the task status changes
Coming to my customer requirements, they wanted to be notified incase the task is reassigned for more than 3 times .In case of a reassign the OnTaskUpdated  callback will be invoked and control will get into the OnTaskUpdated  parallel flow where you can add the required customizations.. So this logic was embedded in this callback flow. After the flow is completed it again goes back and waits in the while loop till next callback event is activated from the workflow service.
The figure defines the human workflow process flow inside the BPEL. The while loop enables the BPEL process instance to wait on pick activity till the task status gets updated to task completion/expiration/error/stale/withdrawn. This brings in multiple options for customization within the BPEL based on the workflow status/updates. This is really good feature using multiple callbacks functionality.