Can I start a new machine from a state stored in my database? #158
Replies: 2 comments 2 replies
|
Went through the 0.38.1 source for this. Here's my take on each question (not a maintainer, so happy to be corrected): 1. Is 2. Supported alternative: the "active state configuration" persistence ( 3. Build once, reuse? Not as shared instances. A state object belongs to one machine, and reusing it in another machine destroys the previous one ( 4. Rebuild per request? Yes, that's the pattern. Build with 5. fun buildWorkflow() = createStdLibStateMachine("order", start = false,
creationArguments = buildCreationArguments { requireNonBlankNames = NonBlankNamesRequirement.STATES }) { /* states */ }
val machine = buildWorkflow()
machine.restoreBySavedStateConfigBlocking(loadSnapshot(id))
machine.processEventBlocking(event)
saveSnapshot(id, machine.captureSavedStateConfig())
machine.destroyBlocking()(Names must be non-blank for snapshots, hence |
|
Hello!
|
Uh oh!
There was an error while loading. Please reload this page.
We are evaluating KStateMachine 0.38.1 for a synchronous Spring MVC and JPA application.
Our database is already the source of truth for each workflow's current state and definition version. The application runs on multiple servers, so we cannot depend on state-machine objects kept in one server's memory.
For each request, we want to:
We would prefer not to store a separate KStateMachine snapshot because it would duplicate the workflow state already stored in our database.
Testing.startFrom() does what we need, but the documentation describes it as a testing helper.
Questions:
Thank you.
All reactions