paed01 / bpmn-engine

BPMN 2.0 execution engine. Open source javascript workflow engine.
MIT License
892 stars 167 forks source link

saving and loading the state #77

Closed mariohmol closed 5 years ago

mariohmol commented 5 years ago

Hi there!

I'm trying to have workflow where will wait for a user interaction. So I was planing to save the state of the flow in a database, and then when the user make his interaction, i can load the state from database and then run this next task.

I'm trying to achieve this using the getState and recover.

https://github.com/mariohmol/bpmn-engine/blob/master/docs/examples/server.js#L31

Using the wait user example: https://github.com/paed01/bpmn-engine/blob/master/docs/Examples.md#listen-for-events

STEPS : What I'm doing:

  1. In the /start I call this example and save the State in array
  2. In /answer I recover from this state and try to get the same listener he stoped before (listener.once('wait',

I tested using const post = api.getPostponed(); but is not returning me a task that i can send a signal to continue the flow.

So i think there is 2 main 'bugs' to investigate:

  1. Between getState and recover.resume, the api is not populating the postponed tasks
  2. I dont see the listeners been called as well
  3. Should I do something to change the idle state to make it execute again?

To make it easy to test, in my repo you can fork and run npm run examples startResume In VSCode u can run the Example task to debug this.

Any ideas on how i can achieve this?

thanks

mariohmol commented 5 years ago

could fix it! Was a matter of await async!

This example with express is in the PR if u are interested to incorporate!

thanks