Skip to content
Snippets Groups Projects

Creating a sketch of the Mealy machine system

Merged Daniel Lyons requested to merge capability-state-machine-prototype into main
3 unresolved threads

Messing around making a prototype of the capability execution state machine system.

Edited by Daniel Lyons

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
27 """
28 An action to take upon performing a transition. We expect to see several implementations
29 of this interface:
30
31 - SendNotification(template, additional_args) that sends a notification with
32 the event and additional arguments
33
34 - StartWorkflow(workflow_name, additional_args) that starts a workflow with the
35 provided name, the event and additional arguments
36 """
37 @abc.abstractmethod
38 def execute(self):
39 pass
40
41
42 class Pattern(abc.ABC):
  • 129 this event, that we would therefore need to act on.
    130
    131 :param event: the event to check
    132 :return: a list of matching capability executions
    133 """
    134 return self.session.query("""
    135 SELECT *
    136 FROM transitions t
    137 JOIN machines m ON t.machine_id = m.id
    138 JOIN capabilities c ON c.machine_id = m.id
    139 JOIN capability_requests cr on cr.capability_name = c.name
    140 JOIN capability_executions ce on cr.capability_request_id = ce.capability_request_id
    141 WHERE %(event)s @? t.pattern AND ce.state = t.from_state
    142 """, {"event": json.dumps(event)})
    143
    144 def build_tables(self):
  • 8 import json
    9
    10
    11 class State(abc.ABC):
    12 """
    13 A state that a machine could reside in.
    14 """
    15 @abc.abstractmethod
    16 def matches(self, other: "State") -> bool:
    17 """
    18 This is most likely implemented by doing a string-equality test.
    19
    20 :param other: the other state to compare to
    21 :return: true if we and the other state match
    22 """
    23 pass
    • I'm confused about the purpose of this method for a state. Can you expound a little on why we'd need to determine if two states match?

    • This is because we can't unconditionally take a transition to a certain state just because we got an event that matches the pattern. The way the Mealy machine works, we have a rule for going from state A to state B, so we have to be sure we're actually in state A.

    • Oh, ok. So can I think of this as a kind of implementation of Python's __eq__?

    • It will probably wind up being "State 1" == "State 2", but I wanted to be explicit that we need to make sure that two states match lower down in the prototype, and I don't want to make an implicit dependency on states being strings.

    • Please register or sign in to reply
  • I think this is a nice baseline. I'd be really interested in seeing one of our capabilities state-machine-ified and what that would look like.

  • Daniel Lyons added 8 commits

    added 8 commits

    Compare with previous version

  • Daniel Lyons marked this merge request as ready

    marked this merge request as ready

  • Daniel Lyons added 2 commits

    added 2 commits

    • e90d444f - 1 commit from branch main
    • 877d9969 - Creating a sketch of the Mealy machine system

    Compare with previous version

  • merged

  • Please register or sign in to reply
    Loading