-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "transitions" based execution machine
This adapts the logic how modules are loaded and sorted for execution. Signed-off-by: Tobias Wolf <[email protected]>
- Loading branch information
1 parent
8c25bb2
commit 07be5c7
Showing
5 changed files
with
132 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from transitions import MachineError | ||
from transitions import Machine as _Machine | ||
from transitions.extensions.states import add_state_features, Tags, Timeout | ||
from typing import Any, Dict | ||
|
||
|
||
@add_state_features(Tags, Timeout) | ||
class Machine(_Machine): # type: ignore | ||
def __init__(self) -> None: | ||
_Machine.__init__(self, states=["uninitialized"], initial="uninitialized") | ||
|
||
def add_migrating_state(self, name: Any, **kwargs: Dict[str, Any]) -> None: | ||
if not isinstance(name, str): | ||
raise MachineError("Migration state name must be string") | ||
self.add_state(name, **kwargs) | ||
|
||
def execute(self) -> None: | ||
self.add_state("migrated") | ||
self.add_ordered_transitions(loop=False) | ||
|
||
try: | ||
while True: | ||
self.next_state() | ||
except MachineError: | ||
if self.state != "migrated": | ||
raise |
Oops, something went wrong.