zutnop / telekom-workflow-engine

An embeddable Java framework for running long-lived business processes
MIT License
27 stars 14 forks source link

How to exit workflow? #23

Closed kaarelp closed 2 years ago

kaarelp commented 2 years ago

I need to exit workflow if condition is met:

factory.start()
   [...]
   .if_(condition)
      .end() //compile error
   .endif()
   [...]
.end();

Is this possible without nested if-blocks or throwing Exceptions?

zutnop commented 2 years ago

No, currently there is no "exit" or other this kind of "GOTO" concept in TWE. Because we haven't had a need.

In one place I have used exception throwing like that:

// UNKNOWN STATUS: fail fast! Can be fixed and then restarted from the workflow admin console.
.else_()
    .call(296, EXAMPLE_SERVICE, "throwIllegalSubstatus", "${exampleParam1}", "${exampleParam2}")
.endIf()

, but the need there isn't "to nicely end", instead it's "to fail fast when some external conditions have changed and we need to develop the workflow further to work with new conditions and then re-try the instance".

It really depends on what kind of logical process you are trying to implement, maybe there's a clear way to express it with current flow statements without needing an "exit" statement? If support for "exit" statements is needed, then one could implement it and submit a pull request :)