Running Background Processes from Workflows
Via the API Task interface, you can start a background process (BGP) and have events triggered on the task matching the end status of the background process. The image below shows a simple workflow where an Approve Recursively Background Process is started when entering the 'Trigger_BGP' state. When the background process is done, one of the transitions out of the state will be performed based on the end status of the background process. For example, if the end status is 'succeeded', the "bgp.succeeded" event will be triggered. If the status fails, the "bgp.failed" event will be triggered. Similar to the 'StateID.Something' (where 'Something' stands for the user's word choice) and 'stibo.import' events, any event beginning with 'bgp.' will be hidden in the STEP Workflow Items editor and on the Object Tasks tab.
In the image below, as soon as a task is released to the 'Trigger_BGP' state, the Approve Recursively with a BGP process script will execute.
Once a BGP has finished, if a particular task / item needs to be investigated, a user can navigate to its State Log tab and view all Background Process IDs that occurred.
To examine additional background process information, go to the BG Processes tab and review the background processes for the relevant workflow or search for the Background Process ID.
If the BGP fails, review the BGP report to determine the reason.
In the case of this 'Approve Recursively' workflow example, the task will be moved to the Failure state, and once the error is fixed, the task can be moved from the Failure state by selecting the event 'Try_Again'. If the BGP is successful, it will move to the Success state.
On Entry Background Process Script
While the script below could be used for other scenarios, two scenarios that this script can be used with workflow for are the following:
- If an object is required to run a translation, and it is mandatory that an object is in the approved state before running the translation.
- If there is any extraction required from the Approved workspace.
The On Entry script that starts the background process is shown below. The last line stores the ID of the started background process in a workflow variable with ID 'BGP ID'. The ApproveRecursiveServiceDescriptor is described in the public API documentation, accessed by clicking the 'Technical Documentation' button on the Start Page.
var task = node.getTaskByID("WorkflowID", "WorkflowStateID"); var serviceDescriptor = com.stibo.services.base.approverecursive.ApproveRecursiveServiceDescriptor; var parameter = new serviceDescriptor.Parameter(); parameter.context = step.getCurrentContext(); parameter.nodes = [node]; var bgp = task.startBackgroundProcess(serviceDescriptor, parameter, "Started from Workflow"); node.getWorkflowInstance(workflow).setSimpleVariable("WorkflowVariableID", bgp.getID());
Note: The 'WorkflowID' and 'WorkflowStateID' in the top line, and 'WorkflowVariableID' in the bottom should be replaced by the users desired workflow information.
The On Entry script in the state 'Trigger_BGP' will look like the image below. Also notice that the image below has filled in the appropriate 'WorkflowID,' 'WorkflowStateID,' and 'WorkflowVariableID' in accordance to the workflow information.