Skip to content

Add tags and metadata to the state machine states #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions serverlessworkflow/sdk/state_machine_extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading