I have a distributed system defined by a sort of "state machine" ( "flow chart" )
each system writes there state in a shared "log"
I'm representing each state as part of a sealed trait and a given "status" for that state
I want to "merge/reduce" to a single status which represents the current progress.
(There are some relaxations in place as not all must succeed in order for the final status to complete successfully)
There are 2 sealed traits representing the flow:
sealed trait System
case object A extends System
case object B extends System
case object C extends System
...
sealed trait Status
case object Pending extends Status
case object InProgress extends Status
case object Success extends Status
case object Fail extends Status
Log:
A, Success
B, Fail
C, Pending
...
...
now there are a set of rules which I use to define a single status reduction
basically it gives a priority
A < B < C, ... < Z
and
Pending < InProgress < Success < Fail
so if there is a status of:
(A, Success)
versus (C, Pending)
I want to reduce it to (C,Pending)
and if
(A,Success)
versus (B, Fail)
I want to reduce it to (B, Fail)
I can model this as a simple integer comparison in my case (possibly with an outlier which I explicitly test for)
I'm not clear how to make the sealed traits comparible/orderable which would make my life way easier
something along these lines is adequate:
def reduce(states: Seq[(System,Status)]) : (System,Status) = {
states.order... {left.system < right.system) && (a.status < b.status) ... possibly another ordering test ....}.tail // take the last one in the ordering
}