Skip to content

Automate a process

The following tutorial shows the automation of an example process.

The process consists of an exclusive gateway and 2 service tasks. A decision must be made, if either service task doX or doY should be executed. After the gateway is evaluated, one service task must be executed to end an instance of the example process.

example.bpmn

To execute an instance of the example process, the process must first be created at the engine, using the BPMN 2.0 XML (see file example.bpmn).

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:8080/processes \
-d "$(jq -n --arg bpmnXml "$(cat example.bpmn)" '{"bpmnProcessId": "example", "bpmnXml": $bpmnXml, "version": "1", "workerId": "curl"}')"

Based on an existing process, identified by BPMN process ID and version, instances can be created. A process instance can hold any data in form of string encoded process variables.

In this example, the initial process data is provided as variable xory, a JSON encoded string with value x.

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:8080/process-instances \
-d '{"bpmnProcessId": "example", "variables": {"xory": {"encoding": "json", "value": "x"}}, "version": "1", "workerId": "curl"}'

When the process engine reaches an exclusive gateway, a job of type EVALUATE_EXCLUSIVE_GATEWAY is created. It must be locked, executed and completed to continue the execution.

In case of an exclusive gateway, a job needs to be completed with a decision that provides the ID of an BPMN element to continue with after the gateway.

Lock job:

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:8080/jobs/lock \
-d '{"limit": 1, "workerId": "curl"}'

Get variables of process instance (to make an decision):

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
"http://127.0.0.1:8080/process-instances/$(date -I)/1/variables"

Complete job with an exclusive gateway decision:

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X PATCH http://127.0.0.1:8080/jobs/$(date -I)/1/complete \
-d '{"completion": {"exclusiveGatewayDecision": "doX"}, "workerId": "curl"}'

When the process engine reaches a service task, a job of type EXECUTE is created. It must be locked, executed and completed to continue the execution.

In case of a service task, no type-specific completion is required.

Lock job:

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:8080/jobs/lock \
-d '{"limit": 1, "workerId": "curl"}'

Complete job, which confirms the execution of service task doX:

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X PATCH http://127.0.0.1:8080/jobs/$(date -I)/2/complete \
-d '{"processVariables": {"result": {"encoding": "json", "value": "x done"}}, "workerId": "curl"}'

Verify that process instance is in state ENDED:

Terminal window
curl -v \
-H "Authorization: ${GO_BPMN_AUTHORIZATION}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:8080/process-instances/query \
-d '{}'