nitram509 / lib-bpmn-engine

A BPMN engine, meant to be embedded in Go applications with minimal hurdles, and a pleasant developer experience using it. This approach can increase transparency for non-developers.
https://nitram509.github.io/lib-bpmn-engine/
MIT License
274 stars 70 forks source link

QUESTION: Process not in COMPLETED state? #118

Closed eriknyk closed 1 year ago

eriknyk commented 1 year ago

QUESTION: Why if we create & run the instance CreateAndRunInstance simple_task.bpmn technically the process finished but if after CreateAndRunInstance() finishes then I dump the instance state it is in state ACTIVE when it looks like it should to has COMPLETED state.

image
        // create a new named engine
    bpmnEngine := bpmn_engine.New("a name")
    // basic example loading a BPMN from file,
    //process, err := bpmnEngine.LoadFromFile("simple_task.bpmn")
    process, err := bpmnEngine.LoadFromFile("simple_user_task.bpmn")

    if err != nil {
        panic("file \"simple_task.bpmn\" can't be read.")
    }
    // register a handler for a service task by defined task type
    bpmnEngine.NewTaskHandler().Id("hello-world").Handler(printContextHandler)

    bpmnEngine.NewTaskHandler().Assignee("assignee").Handler(userTaskHandler())

    // setup some variables
    variables := map[string]interface{}{}
    variables["foo"] = "bar"
    // and execute the process
    instance, err := bpmnEngine.CreateAndRunInstance(process.ProcessKey, variables)
    if err != nil {
        return
    }

    println("InstanceKey: " + strconv.FormatInt(instance.GetInstanceKey(), 10))
    println("State: " + string(instance.GetState()))

Output:

< Hello World >
ElementId                = hello-world
BpmnProcessId            = Simple_Task_Process
ProcessDefinitionKey     = 1664696323368030208
ProcessDefinitionVersion = 1
CreatedAt                = 2023-06-02 13:11:46.710748 -0500 -05 m=+0.003794422
Variable 'foo'           = bar
InstanceKey: 1664696323368030209
State: "ACTIVE"
jinjaghost commented 1 year ago

Hi @eriknyk, in order to help you, can you please provide the userTaskHandler handler function ?

eriknyk commented 1 year ago

I will do, thanks @jinjaghost

nitram509 commented 1 year ago

Hi @eriknyk Indeed, as @jinjaghost mentioned, is important that the task handler sends the "complete" signal. Else, a task is considered un-finished == still active.

Regards Martin

nitram509 commented 1 year ago

Seems answered. If not, feel free to re-open.