99
1010from .PurgeHistoryResult import PurgeHistoryResult
1111from .DurableOrchestrationStatus import DurableOrchestrationStatus
12+ from .EntityStateResponse import EntityStateResponse
1213from .RpcManagementOptions import RpcManagementOptions
1314from .OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
1415from ..models .DurableOrchestrationBindings import DurableOrchestrationBindings
@@ -132,6 +133,56 @@ def create_http_management_payload(self, instance_id: str) -> Dict[str, str]:
132133 """
133134 return self .get_client_response_links (None , instance_id )
134135
136+ async def read_entity_state (
137+ self ,
138+ entityId : EntityId ,
139+ task_hub_name : Optional [str ] = None ,
140+ connection_name : Optional [str ] = None ,
141+ ) -> EntityStateResponse :
142+ """Read the state of the entity.
143+
144+ Parameters
145+ ----------
146+ entityId : EntityId
147+ The EntityId of the targeted entity.
148+ task_hub_name : Optional[str]
149+ The task hub name of the target entity.
150+ connection_name : Optional[str]
151+ The name of the connection string associated with [task_hub_name].
152+
153+ Raises
154+ ------
155+ Exception:
156+ When an unexpected status code is returned
157+
158+ Returns
159+ -------
160+ EntityStateResponse
161+ container object representing the state of the entity
162+ """
163+ options = RpcManagementOptions (
164+ connection_name = connection_name ,
165+ task_hub_name = task_hub_name ,
166+ entity_Id = entityId ,
167+ )
168+
169+ request_url = options .to_url (self ._orchestration_bindings .rpc_base_url )
170+ response = await self ._get_async_request (request_url )
171+
172+ switch_statement = {
173+ 200 : lambda : EntityStateResponse (True , response [1 ]),
174+ 404 : lambda : EntityStateResponse (False ),
175+ }
176+
177+ result = switch_statement .get (response [0 ])
178+
179+ if not result :
180+ raise Exception (
181+ f"The operation failed with an unexpected status code { response [0 ]} "
182+ )
183+
184+ return result ()
185+
135186 def get_client_response_links (
136187 self ,
137188 request : Optional [func .HttpRequest ], instance_id : str ) -> Dict [str , str ]:
@@ -440,6 +491,8 @@ async def wait_for_completion_or_create_check_status_response(
440491 lambda : self ._create_http_response (200 , status .to_json ()),
441492 OrchestrationRuntimeStatus .Failed :
442493 lambda : self ._create_http_response (500 , status .to_json ()),
494+ None :
495+ None
443496 }
444497
445498 result = switch_statement .get (status .runtime_status )
@@ -456,6 +509,7 @@ async def wait_for_completion_or_create_check_status_response(
456509 await sleep (sleep_time )
457510 else :
458511 return self .create_check_status_response (request , instance_id )
512+ return self .create_check_status_response (request , instance_id )
459513
460514 async def signal_entity (self , entityId : EntityId , operation_name : str ,
461515 operation_input : Optional [Any ] = None ,
@@ -640,6 +694,7 @@ async def rewind(self,
640694
641695 response = await self ._post_async_request (request_url , None )
642696 status : int = response [0 ]
697+ ex_msg : str = ""
643698 if status == 200 or status == 202 :
644699 return
645700 elif status == 404 :
@@ -648,6 +703,9 @@ async def rewind(self,
648703 elif status == 410 :
649704 ex_msg = "The rewind operation is only supported on failed orchestration instances."
650705 raise Exception (ex_msg )
651- else :
706+ elif isinstance ( response [ 1 ], str ) :
652707 ex_msg = response [1 ]
653708 raise Exception (ex_msg )
709+ else :
710+ ex_msg = "Received unexpected payload from the durable-extension: " + str (response )
711+ raise Exception (ex_msg )
0 commit comments