Skip to content

Commit 760f707

Browse files
committed
Improve locked_by parsing
1 parent faf6cc4 commit 760f707

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

durabletask/entities/entity_instance_id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def parse(entity_id: str) -> Optional["EntityInstanceId"]:
3737
_, entity, key = entity_id.split("@", 2)
3838
return EntityInstanceId(entity=entity, key=key)
3939
except ValueError as ex:
40-
raise ValueError("Invalid entity ID format", ex)
40+
raise ValueError(f"Invalid entity ID format: {entity_id}", ex)

durabletask/entities/entity_metadata.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self,
3838
self.id = id
3939
self.last_modified = last_modified
4040
self.backlog_queue_size = backlog_queue_size
41-
self.locked_by = locked_by
41+
self._locked_by = locked_by
4242
self.includes_state = includes_state
4343
self._state = state
4444

@@ -81,3 +81,17 @@ def get_state(self, intended_type: Optional[Type[TState]] = None) -> Union[None,
8181
raise TypeError(
8282
f"Could not convert state of type '{type(self._state).__name__}' to '{intended_type.__name__}'"
8383
) from ex
84+
85+
def get_locked_by(self) -> Optional[EntityInstanceId]:
86+
"""Get the identifier of the worker that currently holds the lock on the entity.
87+
88+
Returns
89+
-------
90+
str
91+
The identifier of the worker that currently holds the lock on the entity.
92+
"""
93+
if not self._locked_by:
94+
return None
95+
96+
# Will throw ValueError if the format is invalid
97+
return EntityInstanceId.parse(self._locked_by)

tests/durabletask-azuremanaged/test_dts_class_based_entities_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def do_nothing(self, _):
6363
state = c.get_entity(entity_id)
6464
assert state is not None
6565
assert state.id == entity_id
66-
assert state.locked_by is None
66+
assert state.get_locked_by() is None
6767
assert state.last_modified > datetime.now(timezone.utc)
6868
assert state.get_state(int) == 1
6969

tests/durabletask-azuremanaged/test_dts_function_based_entities_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def empty_entity(ctx: entities.EntityContext, _):
6363
state = c.get_entity(entity_id)
6464
assert state is not None
6565
assert state.id == entity_id
66-
assert state.locked_by is None
66+
assert state.get_locked_by() is None
6767
assert state.last_modified > datetime.now(timezone.utc)
6868
assert state.get_state(int) == 1
6969

0 commit comments

Comments
 (0)