Skip to content

Commit 9a74b6d

Browse files
committed
Entities kind of working
1 parent c62edb7 commit 9a74b6d

3 files changed

Lines changed: 126 additions & 40 deletions

File tree

durabletask/internal/helpers.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from google.protobuf import timestamp_pb2, wrappers_pb2
99

10+
from durabletask.entities.entity_instance_id import EntityInstanceId
1011
import durabletask.internal.orchestrator_service_pb2 as pb
1112

1213
# TODO: The new_xxx_event methods are only used by test code and should be moved elsewhere
@@ -195,26 +196,30 @@ def new_schedule_task_action(id: int, name: str, encoded_input: Optional[str],
195196
))
196197

197198

198-
def new_call_entity_action(id: int, name: str, encoded_input: Optional[str]):
199+
def new_call_entity_action(id: int, parent_instance_id: str, entity_id: EntityInstanceId, operation: str, encoded_input: Optional[str]):
199200
return pb.OrchestratorAction(id=id, sendEntityMessage=pb.SendEntityMessageAction(entityOperationCalled=pb.EntityOperationCalledEvent(
200-
requestId=None,
201-
targetInstanceId=get_string_value(name),
202-
input=get_string_value(encoded_input)
201+
requestId=f"{parent_instance_id}:{id}",
202+
parentInstanceId=get_string_value(parent_instance_id),
203+
targetInstanceId=get_string_value(str(entity_id)),
204+
input=get_string_value(encoded_input),
205+
operation=operation
203206
)))
204207

205208

206-
def new_signal_entity_action(id: int, name: str):
209+
def new_signal_entity_action(id: int, entity_id: EntityInstanceId, operation: str, encoded_input: Optional[str]):
207210
return pb.OrchestratorAction(id=id, sendEntityMessage=pb.SendEntityMessageAction(entityOperationSignaled=pb.EntityOperationSignaledEvent(
208-
requestId=None,
209-
targetInstanceId=get_string_value(name)
211+
requestId=f"{entity_id}:{id}",
212+
targetInstanceId=get_string_value(str(entity_id)),
213+
operation=operation,
214+
input=get_string_value(encoded_input)
210215
)))
211216

212217

213-
def new_lock_entities_action(id: int, instance_id: str, critical_section_id: str, entity_ids: list[str]):
218+
def new_lock_entities_action(id: int, parent_instance_id: str, critical_section_id: str, entity_ids: list[EntityInstanceId]):
214219
return pb.OrchestratorAction(id=id, sendEntityMessage=pb.SendEntityMessageAction(entityLockRequested=pb.EntityLockRequestedEvent(
215-
parentInstanceId=get_string_value(instance_id),
220+
parentInstanceId=get_string_value(parent_instance_id),
216221
criticalSectionId=critical_section_id,
217-
lockSet=entity_ids,
222+
lockSet=[str(eid) for eid in entity_ids],
218223
position=0
219224
)))
220225

@@ -236,7 +241,10 @@ def convert_to_entity_batch_request(req: pb.EntityRequest) -> tuple[pb.EntityBat
236241
operation=op.entityOperationCalled.operation,
237242
input=op.entityOperationCalled.input))
238243
operation_infos.append(pb.OperationInfo(requestId=op.entityOperationCalled.requestId,
239-
responseDestination=None))
244+
responseDestination=pb.OrchestrationInstance(
245+
instanceId=op.entityOperationCalled.parentInstanceId.value,
246+
executionId=op.entityOperationCalled.parentExecutionId
247+
)))
240248

241249
return batch_request, operation_infos
242250

durabletask/task.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,17 @@ def call_activity(self, activity: Union[Activity[TInput, TOutput], str], *,
141141
pass
142142

143143
@abstractmethod
144-
def call_entity(self, entity: EntityInstanceId, *,
144+
def call_entity(self, entity: EntityInstanceId,
145+
operation: str, *,
145146
input: Optional[TInput] = None):
146147
"""Schedule entity function for execution.
147148
148149
Parameters
149150
----------
150151
entity: EntityInstanceId
151152
The ID of the entity instance to call.
153+
operation: str
154+
The name of the operation to invoke on the entity.
152155
input: Optional[TInput]
153156
The optional JSON-serializable input to pass to the entity function.
154157
@@ -162,14 +165,20 @@ def call_entity(self, entity: EntityInstanceId, *,
162165
@abstractmethod
163166
def signal_entity(
164167
self,
165-
entity_id: EntityInstanceId
168+
entity_id: EntityInstanceId,
169+
operation_name: str,
170+
input: Optional[TInput] = None
166171
) -> None:
167172
"""Signal an entity function for execution.
168173
169174
Parameters
170175
----------
171176
entity_id: EntityInstanceId
172177
The ID of the entity instance to signal.
178+
operation_name: str
179+
The name of the operation to invoke on the entity.
180+
input: Optional[TInput]
181+
The optional JSON-serializable input to pass to the entity function.
173182
"""
174183
pass
175184

0 commit comments

Comments
 (0)