nitram509/lib-bpmn-engine

How to implement user task?

Closed this issue · 3 comments

I'm exploring user task function, there is example at https://github.com/nitram509/lib-bpmn-engine/blob/main/docs/examples/pause_user_tasks/pause_user_tasks.go
however, I can't understand how to implement it, support the workflow shall pause user task step, waiting further instruction right? Is there any better example?

@kstan79

Since user tasks are asynchronous by nature, the lib-bpmn-engine is designed to pause a workflow and continue later.

In the example, Line 11

instance, _ := bpmnEngine.CreateAndRunInstance(process.ProcessKey, nil)

This is where your workflow is started in the engine until the point, where the user task happens,
then the handler is called.
Since the handler notifies the user for action (Line 21) it then just returns, so then engine will pause the workflow and return the control to your application, in Line 12.
Now, your application must somehow get the input from the user and then "continue" the workflow instance, as shown in Line 13.
Since the user task was paused, the same task handler will be called and now the handler knows, that the desired user input is present and can finally call job.Complete() to signal the engine to continue the workflow.

Typically, you need to store the user input in some database or similar.
In the example you see if externalEvent == "user is done" { - this must be your logic, which baybe fetches user input from a database or similar - OR the user input comes in via API-Request ... completely up to your design and needs.

Does this make more sense to you?

ok. seems i need to build a full structure with database in order to continue evaluate. Will update again afterwards.

OK, thank you for the feedback.
Please, keep in mind the feature of loading/storing BPMN state from/into a database is still on the roadmap:
https://github.com/nitram509/lib-bpmn-engine/milestone/3

I consider this question answered.
If you have further questions, don't hesitate to create new issues/questions :)