forked from serverlessworkflow/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_machine_extensions.py
More file actions
41 lines (31 loc) · 1.06 KB
/
state_machine_extensions.py
File metadata and controls
41 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from transitions.extensions.states import add_state_features, Tags, State
from transitions.extensions import (
HierarchicalMachine,
GraphMachine,
HierarchicalGraphMachine,
)
class Metadata(State):
"""Allows states to have metadata.
Attributes:
metadata (dict): A dictionary with the state metadata.
"""
def __init__(self, *args, **kwargs):
"""
Args:
**kwargs: If kwargs contains `metadata`, assign them to the attribute.
"""
self.metadata = kwargs.pop("metadata", None)
super(Metadata, self).__init__(*args, **kwargs)
def __getattr__(self, key):
if value := self.metadata.get(key) is not None:
return value
return super(Metadata, self).__getattribute__(key)
@add_state_features(Tags, Metadata)
class CustomHierarchicalMachine(HierarchicalMachine):
pass
@add_state_features(Tags, Metadata)
class CustomHierarchicalGraphMachine(HierarchicalGraphMachine):
pass
@add_state_features(Tags, Metadata)
class CustomGraphMachine(GraphMachine):
pass