88from abc import ABC , abstractmethod
99from datetime import datetime , timedelta
1010from typing import Any , Callable , Generator , Generic , Optional , Type , TypeVar , Union , overload
11+ import uuid
1112
1213from durabletask .entities import DurableEntity , EntityInstanceId , EntityLock
14+ from durabletask .internal import shared
1315from durabletask .internal .entity_state_shim import StateShim
1416import durabletask .internal .helpers as pbh
1517import durabletask .internal .orchestrator_service_pb2 as pb
@@ -141,7 +143,7 @@ def call_activity(self, activity: Union[Activity[TInput, TOutput], str], *,
141143 pass
142144
143145 @abstractmethod
144- def call_entity (self , entity : EntityInstanceId ,
146+ def call_entity (self , entity : EntityInstanceId ,
145147 operation : str , * ,
146148 input : Optional [TInput ] = None ):
147149 """Schedule entity function for execution.
@@ -545,10 +547,10 @@ def operation(self) -> str:
545547 The operation associated with this entity invocation.
546548 """
547549 return self ._operation
548-
550+
549551 @overload
550552 def get_state (self , intended_type : Type [TState ]) -> Optional [TState ]: ...
551-
553+
552554 @overload
553555 def get_state (self , intended_type : None = None ) -> Any : ...
554556
@@ -558,6 +560,37 @@ def get_state(self, intended_type: Optional[Type[TState]] = None) -> Optional[TS
558560 def set_state (self , new_state : Any ):
559561 self ._state .set_state (new_state )
560562
563+ def signal_entity (self , entity_instance_id : EntityInstanceId , operation : str , input : Optional [Any ] = None ) -> None :
564+ encoded_input = shared .to_json (input ) if input is not None else None
565+ self ._state .add_operation_action (
566+ pb .OperationAction (
567+ sendSignal = pb .SendSignalAction (
568+ instanceId = str (entity_instance_id ),
569+ name = operation ,
570+ input = pbh .get_string_value (encoded_input ),
571+ scheduledTime = None ,
572+ requestTime = None ,
573+ parentTraceContext = None ,
574+ )
575+ )
576+ )
577+
578+ def schedule_new_orchestration (self , orchestration_name : str , input : Optional [Any ] = None , instance_id : Optional [str ] = None ) -> None :
579+ encoded_input = shared .to_json (input ) if input is not None else None
580+ self ._state .add_operation_action (
581+ pb .OperationAction (
582+ startNewOrchestration = pb .StartNewOrchestrationAction (
583+ instanceId = instance_id if instance_id else uuid .uuid4 ().hex , # TODO: Should this be non-none?
584+ name = orchestration_name ,
585+ input = pbh .get_string_value (encoded_input ),
586+ version = None ,
587+ scheduledTime = None ,
588+ requestTime = None ,
589+ parentTraceContext = None
590+ )
591+ )
592+ )
593+
561594 @property
562595 def entity_id (self ) -> EntityInstanceId :
563596 """Get the ID of the entity instance.
0 commit comments