transitions
transitions copied to clipboard
Practice on collecting states from multiple machine
I'm trying to use transistions to implment a scheduler for distributed system.
Let's say, there are three participants A, B, C
in a distrubted task; scheduler runs on each participant to broadcast its own state periodicity and collect peer state to make callback to its own participant.
Each participant have states ['unspecified', 'inited', 'prepared, 'done', 'error']
;
to_prepared
should be triggered when all participants are inited
.
to_done(execute)
should be triggered when all participants are prepared
.
For more detail,
- scheduler of
A
isinited
and all peers areunspecified
on initial; - after receiving "inited" messages from
B
andC
, scheduler callto_prepared
; sceduler ofA
becomeprepared
after the trigger - after receiving "prepared" messages from all peers, scheduler call
to_done
Since messages that send from one to another participant may be lost, or disordering, to be robust, peer state can be skipped, e.g. B
from unspecified to prepared from the perspective of A [ B received A and C inited messages, but A missed the "inited" message from B].
I'd like to implement the scheduler by HSM at the first place, but it seems much more complicated. paralleled states cannot be inherited between top level states, then the skipped states are not able to be presented. For now, the scheduler is implemented in a separate state machine, process each message to update peer state, and after that, it calculates the overall state of peers to identify its state.
What's the best practice of such scenario? Can it be done by nested state machine?