oliverzy / process-engine.js

Node.js Business Process/Workflow Engine
128 stars 32 forks source link

Better examples and clearer flow samples #3

Open nicolasembleton opened 10 years ago

nicolasembleton commented 10 years ago

I think it would be very beneficial to have a clearer flow sample. There are many examples of how individually things work, but I find that the following things are unclear to me, even though I've looked at the sources, examples and tests:

Sorry for the dummy questions, but even after a couple hours of trial & error, it's still not very clear to me the way it should work. But I really love the way it's built and the features so I try to have it working.

oliverzy commented 10 years ago

It's not dummy at all. Process Engine describes the workflow using tasks and flows. The built-in task types:

The flow is something to connect the tasks and can take a condition function if the from task is decision task.

human task service is used to manipulate the task list.

Therefore, for question 1, you can manipulate external data in service task, basically you provide a function that take a process variables and complete function. You can do whatever things in your function, once it's done, call complete to let engine continue execution.

'Auto UW': {type: 'service', action: function (variables, complete) {
      variables.autoUnderwritingResult = variables.age < 60;
      console.log('Auto underwriting service task result:', variables.autoUnderwritingResult);
      complete();
    }}

for question 2, you need to use 'human' task type to model the task that needs to be completed by a user. And once it's done, you can call humanTaskService.complete to let the engine continue execution. For this one, you can see test/Insurance.spec.js for complete code.

Please let me know if you have any other questions.

nicolasembleton commented 10 years ago

Thanks. I think I got it now.

Is it possible to execute code from the action: fn() handler for a human task?

oliverzy commented 10 years ago

Because process instance is a event emitter, you can attach listener on it to listen after event.

processInstance.on('before', function (task) {
// write your code here
console.log(task);      
});
nicolasembleton commented 10 years ago

Gotcha. Pretty nice. Didn't think about that... I think it would just need 1 real-world example with access to outside data, persistence and a couple things like that to make it really practical and helpful to get started.

But thanks. Got it to work nicely.

oliverzy commented 10 years ago

Yes, agree.My daily work is enterprise Java stuff. This project is my side project that inspired by some Java process engine I used but rather lightweight. Glad to see you like it.