gocardless/statesman

Advice for multiple state machines on the same model?

hale opened this issue · 4 comments

hale commented

Hi and thanks for the continued development and support of Statesman, we've gotten a lot of mileage from it.

Can I ask for your advice or instructions on running more than one state machine against a single model?

I saw there was an existing thread from 2016 about issues around this, I'm just wondering if it's something you have experience with and can advise on the best approach.

Thanks :)
Phil

I think that likely depends on the scenario, one conceptual thing should not have more than one state machine, because that single state machine should handle all possible states and transitions for that "thing". Could you tell us more about your use-case?

hale commented

Hm that's interesting.

The use case is that we have two different 'sides' of the application, one customer-facing and the other for administrators.

What we're doing is analogous to publishing a book. We have authors that can move their book into different states (draft, writing, editing, revising) and editors that have another set of actions / state.

I think you could be right though, I like what you said here:

one conceptual thing should not have more than one state machine, because that single state machine should handle all possible states and transitions for that "thing"

Thanks, I'll close this for now. 👍

No problem @hale if you need someone to bounce the ideas off please feel free to give me a prod.

I've made a gem that handles this scenario for statesman for those interested https://github.com/chaadow/statesman-multi_state