in azure/durable_functions/entity.py [0:0]
def handle(self, context: DurableEntityContext, batch: List[Dict[str, Any]]) -> str:
"""Handle the execution of the user-defined entity function.
Loops over the batch, which serves to specify inputs to the entity,
and collects results and generates a final state, which are returned.
Parameters
----------
context: DurableEntityContext
The entity context of the entity, which the user interacts with as their Durable API
Returns
-------
str
A JSON-formatted string representing the output state, results, and exceptions for the
entity execution.
"""
response = EntityState(results=[], signals=[])
for operation_data in batch:
result: Any = None
is_error: bool = False
start_time: datetime = datetime.now()
try:
# populate context
operation = operation_data["name"]
if operation is None:
message = "Durable Functions Internal Error:"\
"Entity operation was missing a name field"
raise InternalEntityException(message)
context._operation = operation
context._input = operation_data["input"]
self.fn(context)
result = context._result
except InternalEntityException as e:
raise e
except Exception as e:
is_error = True
result = str(e)
duration: int = self._elapsed_milliseconds_since(start_time)
operation_result = OperationResult(
is_error=is_error,
duration=duration,
result=result
)
response.results.append(operation_result)
response.state = context._state
response.entity_exists = context._exists
return response.to_json_string()