9
9
10
10
from .PurgeHistoryResult import PurgeHistoryResult
11
11
from .DurableOrchestrationStatus import DurableOrchestrationStatus
12
+ from .EntityStateResponse import EntityStateResponse
12
13
from .RpcManagementOptions import RpcManagementOptions
13
14
from .OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
14
15
from ..models .DurableOrchestrationBindings import DurableOrchestrationBindings
@@ -132,6 +133,56 @@ def create_http_management_payload(self, instance_id: str) -> Dict[str, str]:
132
133
"""
133
134
return self .get_client_response_links (None , instance_id )
134
135
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
+
135
186
def get_client_response_links (
136
187
self ,
137
188
request : Optional [func .HttpRequest ], instance_id : str ) -> Dict [str , str ]:
@@ -440,6 +491,8 @@ async def wait_for_completion_or_create_check_status_response(
440
491
lambda : self ._create_http_response (200 , status .to_json ()),
441
492
OrchestrationRuntimeStatus .Failed :
442
493
lambda : self ._create_http_response (500 , status .to_json ()),
494
+ None :
495
+ None
443
496
}
444
497
445
498
result = switch_statement .get (status .runtime_status )
@@ -456,6 +509,7 @@ async def wait_for_completion_or_create_check_status_response(
456
509
await sleep (sleep_time )
457
510
else :
458
511
return self .create_check_status_response (request , instance_id )
512
+ return self .create_check_status_response (request , instance_id )
459
513
460
514
async def signal_entity (self , entityId : EntityId , operation_name : str ,
461
515
operation_input : Optional [Any ] = None ,
@@ -640,6 +694,7 @@ async def rewind(self,
640
694
641
695
response = await self ._post_async_request (request_url , None )
642
696
status : int = response [0 ]
697
+ ex_msg : str = ""
643
698
if status == 200 or status == 202 :
644
699
return
645
700
elif status == 404 :
@@ -648,6 +703,9 @@ async def rewind(self,
648
703
elif status == 410 :
649
704
ex_msg = "The rewind operation is only supported on failed orchestration instances."
650
705
raise Exception (ex_msg )
651
- else :
706
+ elif isinstance ( response [ 1 ], str ) :
652
707
ex_msg = response [1 ]
653
708
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