Skip to content

Commit f66abf4

Browse files
committed
Add SDK docs for expoded methods
1 parent a993cfc commit f66abf4

File tree

4 files changed

+115
-3
lines changed

4 files changed

+115
-3
lines changed

durabletask/entities/durable_entity.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,61 @@ def get_state(self, intended_type: None = None, default: Any = None) -> Any:
2323
...
2424

2525
def get_state(self, intended_type: Optional[Type[TState]] = None, default: Optional[TState] = None) -> Optional[TState] | Any:
26+
"""Get the current state of the entity, optionally converting it to a specified type.
27+
28+
Parameters
29+
----------
30+
intended_type : Type[TState] | None, optional
31+
The type to which the state should be converted. If None, the state is returned as-is.
32+
default : TState, optional
33+
The default value to return if the state is not found or cannot be converted.
34+
35+
Returns
36+
-------
37+
TState | Any
38+
The current state of the entity, optionally converted to the specified type.
39+
"""
2640
return self.entity_context.get_state(intended_type, default)
2741

2842
def set_state(self, state: Any):
43+
"""Set the state of the entity to a new value.
44+
45+
Parameters
46+
----------
47+
new_state : Any
48+
The new state to set for the entity.
49+
"""
2950
self.entity_context.set_state(state)
3051

3152
def signal_entity(self, entity_instance_id: EntityInstanceId, operation: str, input: Optional[Any] = None) -> None:
53+
"""Signal another entity to perform an operation.
54+
55+
Parameters
56+
----------
57+
entity_instance_id : EntityInstanceId
58+
The ID of the entity instance to signal.
59+
operation : str
60+
The operation to perform on the entity.
61+
input : Any, optional
62+
The input to provide to the entity for the operation.
63+
"""
3264
self.entity_context.signal_entity(entity_instance_id, operation, input)
3365

3466
def schedule_new_orchestration(self, orchestration_name: str, input: Optional[Any] = None, instance_id: Optional[str] = None) -> str:
67+
"""Schedule a new orchestration instance.
68+
69+
Parameters
70+
----------
71+
orchestration_name : str
72+
The name of the orchestration to schedule.
73+
input : Any, optional
74+
The input to provide to the new orchestration.
75+
instance_id : str, optional
76+
The instance ID to assign to the new orchestration. If None, a new ID will be generated.
77+
78+
Returns
79+
-------
80+
str
81+
The instance ID of the scheduled orchestration.
82+
"""
3583
return self.entity_context.schedule_new_orchestration(orchestration_name, input, instance_id=instance_id)

durabletask/entities/entity_context.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,44 @@ def get_state(self, intended_type: None = None, default: Any = None) -> Any:
5555
...
5656

5757
def get_state(self, intended_type: Optional[Type[TState]] = None, default: Optional[TState] = None) -> Optional[TState] | Any:
58+
"""Get the current state of the entity, optionally converting it to a specified type.
59+
60+
Parameters
61+
----------
62+
intended_type : Type[TState] | None, optional
63+
The type to which the state should be converted. If None, the state is returned as-is.
64+
default : TState, optional
65+
The default value to return if the state is not found or cannot be converted.
66+
67+
Returns
68+
-------
69+
TState | Any
70+
The current state of the entity, optionally converted to the specified type.
71+
"""
5872
return self._state.get_state(intended_type, default)
5973

6074
def set_state(self, new_state: Any):
75+
"""Set the state of the entity to a new value.
76+
77+
Parameters
78+
----------
79+
new_state : Any
80+
The new state to set for the entity.
81+
"""
6182
self._state.set_state(new_state)
6283

6384
def signal_entity(self, entity_instance_id: EntityInstanceId, operation: str, input: Optional[Any] = None) -> None:
85+
"""Signal another entity to perform an operation.
86+
87+
Parameters
88+
----------
89+
entity_instance_id : EntityInstanceId
90+
The ID of the entity instance to signal.
91+
operation : str
92+
The operation to perform on the entity.
93+
input : Any, optional
94+
The input to provide to the entity for the operation.
95+
"""
6496
encoded_input = shared.to_json(input) if input is not None else None
6597
self._state.add_operation_action(
6698
pb.OperationAction(
@@ -76,6 +108,22 @@ def signal_entity(self, entity_instance_id: EntityInstanceId, operation: str, in
76108
)
77109

78110
def schedule_new_orchestration(self, orchestration_name: str, input: Optional[Any] = None, instance_id: Optional[str] = None) -> str:
111+
"""Schedule a new orchestration instance.
112+
113+
Parameters
114+
----------
115+
orchestration_name : str
116+
The name of the orchestration to schedule.
117+
input : Any, optional
118+
The input to provide to the new orchestration.
119+
instance_id : str, optional
120+
The instance ID to assign to the new orchestration. If None, a new ID will be generated.
121+
122+
Returns
123+
-------
124+
str
125+
The instance ID of the scheduled orchestration.
126+
"""
79127
encoded_input = shared.to_json(input) if input is not None else None
80128
if not instance_id:
81129
instance_id = uuid.uuid4().hex

durabletask/entities/entity_instance_id.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ def __lt__(self, other):
2121

2222
@staticmethod
2323
def parse(entity_id: str) -> Optional["EntityInstanceId"]:
24+
"""Parse a string representation of an entity ID into an EntityInstanceId object.
25+
26+
Parameters
27+
----------
28+
entity_id : str
29+
The string representation of the entity ID, in the format '@entity@key'.
30+
31+
Returns
32+
-------
33+
Optional[EntityInstanceId]
34+
The parsed EntityInstanceId object, or None if the input is None.
35+
"""
2436
try:
2537
_, entity, key = entity_id.split("@", 2)
2638
return EntityInstanceId(entity=entity, key=key)

durabletask/task.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ def signal_entity(
181181
pass
182182

183183
@abstractmethod
184-
def lock_entities(self, entities: list[EntityInstanceId]) -> EntityLock:
185-
"""Lock the specified entity instances for the duration of the orchestration.
184+
def lock_entities(self, entities: list[EntityInstanceId]) -> Task[EntityLock]:
185+
"""Creates a Task object that locks the specified entity instances.
186+
187+
The locks will be acquired the next time the orchestrator yields.
188+
Best practice is to immediately yield this Task and enter the returned EntityLock.
189+
The lock is released when the EntityLock is exited.
186190
187191
Parameters
188192
----------
@@ -192,7 +196,7 @@ def lock_entities(self, entities: list[EntityInstanceId]) -> EntityLock:
192196
Returns
193197
-------
194198
EntityLock
195-
A disposable object that acquires and releases the locks when initialized or disposed.
199+
A context manager object that releases the locks when exited.
196200
"""
197201
pass
198202

0 commit comments

Comments
 (0)