Designing state machines
21–30 of 58 posts
Re: Designing state machines
#22Re: Designing state machines
#23What about the DB side of things ? How do you model the state graph in the DB ? I have been thinking of using Postgresql CTE to do this. When a cycle occurs, I just create a new step to the dB. Anyone from CRM startups who have interesting learnings here ?
If you mean modeling the state graph itself, it's usually not modeled in the db but only in the code. It could indeed be interesting to store the graph itself if it evolves often, or at least a version number. If you were speaking about storing the instances lifecycles, a simple model using a RDBS is to store one row per transition event in a separate table. This is what the papertrail[1] gem does for example. [1] ht…
Re: Designing state machines
#24I have used an "improved" version of it https://github.com/andreineculau/cosmogol-abnf when working on https://github.com/for-GET/http-decision-diagram
Re: Designing state machines
#25Anyway, I find the concept of "events" a bit weird in this case and I prefer to work with "states" only (state transitions rather than events that change the state). It seems like an unnecessary abstraction to think in terms of an event rather than a state.
Re: Designing state machines
#26Re: Designing state machines
#27I can't recommend Akka's state machines enough. It's an incredibly simple and rock solid state machines built right into the library. ( http://doc.akka.io/docs/akka/snapshot/scala/fsm.html ) We're already on a Play/Scala backend so adding these was incredibly easy for us, but I think they're one of the hidden amazing features of the akka/scala world.
I just looked through and I may have missed it but do you know if this does distributed FSM management?
0 -http://doc.akka.io/docs/akka/current/scala/index-network.htm...
1 - http://doc.akka.io/docs/akka/current/scala/cluster-usage.htm...
Re: Designing state machines
#28Anyone got tips for working with FSMs in REST and/or MVC? Very rarely do you find HTTP verbs match FSM events leading to a fudge somewhere
Instead then of mapping CRUD operations to HTTP, you would map your application semantics to HTTP methods via link relations. Link relations let you go as far past CRUD as you would like to go depending on your domain and allow you to describe your states and state machine.
I always think a good way to think about a hypermedia state machine is in the context of HTML. Consider a todo app example. You might enter the application and get an empty list of todo items. If you have permissions to add a todo, you might have a "create todo" HTML form. Once you use that form, that todo has a new form called "mark complete." Once invoked, that todo has new transitions called "mark incomplete" or "archive." Once archived, you might see a new form for "unarchive." All of this captures the state machine and transitions in the REST API itself using domain-specific semantics.
Of course, there are other ways of solving this problem, but REST with hypermedia is a great way to work with state machines. There are lots of hypermedia JSON formats out there if you're interested in exploring (e.g. HAL, Siren, Collection+JSON, etc.).
Re: Designing state machines
#29What a coincidence, I've been working on a PHP state machine implementation myself in the last few days. Anyway, I find the concept of "events" a bit weird in this case and I prefer to work with "states" only (state transitions rather than events that change the state). It seems like an unnecessary abstraction to think in terms of an event rather than a state.
Re: Designing state machines
#30I can't recommend Akka's state machines enough. It's an incredibly simple and rock solid state machines built right into the library. ( http://doc.akka.io/docs/akka/snapshot/scala/fsm.html ) We're already on a Play/Scala backend so adding these was incredibly easy for us, but I think they're one of the hidden amazing features of the akka/scala world.