durabletask 0.0.0.dev64__tar.gz → 0.0.0.dev66__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/PKG-INFO +1 -1
  2. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/client.py +191 -11
  3. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/entities/__init__.py +3 -1
  4. durabletask-0.0.0.dev66/durabletask/entities/entity_instance_id.py +84 -0
  5. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/entities/entity_metadata.py +9 -5
  6. durabletask-0.0.0.dev66/durabletask/entities/entity_operation_failed_exception.py +15 -0
  7. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/helpers.py +7 -0
  8. durabletask-0.0.0.dev66/durabletask/internal/json_encode_output_exception.py +12 -0
  9. durabletask-0.0.0.dev66/durabletask/internal/orchestrator_service_pb2.py +312 -0
  10. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/orchestrator_service_pb2.pyi +186 -22
  11. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/orchestrator_service_pb2_grpc.py +132 -0
  12. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/proto_task_hub_sidecar_service_stub.py +3 -0
  13. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/worker.py +67 -29
  14. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask.egg-info/PKG-INFO +1 -1
  15. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask.egg-info/SOURCES.txt +2 -0
  16. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/pyproject.toml +1 -1
  17. durabletask-0.0.0.dev64/durabletask/entities/entity_instance_id.py +0 -42
  18. durabletask-0.0.0.dev64/durabletask/internal/orchestrator_service_pb2.py +0 -270
  19. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/LICENSE +0 -0
  20. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/README.md +0 -0
  21. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/__init__.py +0 -0
  22. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/entities/durable_entity.py +0 -0
  23. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/entities/entity_context.py +0 -0
  24. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/entities/entity_lock.py +0 -0
  25. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/entity_state_shim.py +0 -0
  26. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/exceptions.py +0 -0
  27. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/grpc_interceptor.py +0 -0
  28. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/orchestration_entity_context.py +0 -0
  29. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/internal/shared.py +0 -0
  30. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/py.typed +0 -0
  31. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask/task.py +0 -0
  32. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask.egg-info/dependency_links.txt +0 -0
  33. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask.egg-info/requires.txt +0 -0
  34. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/durabletask.egg-info/top_level.txt +0 -0
  35. {durabletask-0.0.0.dev64 → durabletask-0.0.0.dev66}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: durabletask
3
- Version: 0.0.0.dev64
3
+ Version: 0.0.0.dev66
4
4
  Summary: A Durable Task Client SDK for Python
5
5
  License: MIT License
6
6
 
@@ -6,10 +6,9 @@ import uuid
6
6
  from dataclasses import dataclass
7
7
  from datetime import datetime, timezone
8
8
  from enum import Enum
9
- from typing import Any, Optional, Sequence, TypeVar, Union
9
+ from typing import Any, List, Optional, Sequence, TypeVar, Union
10
10
 
11
11
  import grpc
12
- from google.protobuf import wrappers_pb2
13
12
 
14
13
  from durabletask.entities import EntityInstanceId
15
14
  from durabletask.entities.entity_metadata import EntityMetadata
@@ -57,6 +56,39 @@ class OrchestrationState:
57
56
  self.failure_details)
58
57
 
59
58
 
59
+ @dataclass
60
+ class OrchestrationQuery:
61
+ created_time_from: Optional[datetime] = None
62
+ created_time_to: Optional[datetime] = None
63
+ runtime_status: Optional[List[OrchestrationStatus]] = None
64
+ # Some backends don't respond well with max_instance_count = None, so we use the integer limit for non-paginated
65
+ # results instead.
66
+ max_instance_count: Optional[int] = (1 << 31) - 1
67
+ fetch_inputs_and_outputs: bool = False
68
+
69
+
70
+ @dataclass
71
+ class EntityQuery:
72
+ instance_id_starts_with: Optional[str] = None
73
+ last_modified_from: Optional[datetime] = None
74
+ last_modified_to: Optional[datetime] = None
75
+ include_state: bool = True
76
+ include_transient: bool = False
77
+ page_size: Optional[int] = None
78
+
79
+
80
+ @dataclass
81
+ class PurgeInstancesResult:
82
+ deleted_instance_count: int
83
+ is_complete: bool
84
+
85
+
86
+ @dataclass
87
+ class CleanEntityStorageResult:
88
+ empty_entities_removed: int
89
+ orphaned_locks_released: int
90
+
91
+
60
92
  class OrchestrationFailedError(Exception):
61
93
  def __init__(self, message: str, failure_details: task.FailureDetails):
62
94
  super().__init__(message)
@@ -73,6 +105,12 @@ def new_orchestration_state(instance_id: str, res: pb.GetInstanceResponse) -> Op
73
105
 
74
106
  state = res.orchestrationState
75
107
 
108
+ new_state = parse_orchestration_state(state)
109
+ new_state.instance_id = instance_id # Override instance_id with the one from the request, to match old behavior
110
+ return new_state
111
+
112
+
113
+ def parse_orchestration_state(state: pb.OrchestrationState) -> OrchestrationState:
76
114
  failure_details = None
77
115
  if state.failureDetails.errorMessage != '' or state.failureDetails.errorType != '':
78
116
  failure_details = task.FailureDetails(
@@ -81,7 +119,7 @@ def new_orchestration_state(instance_id: str, res: pb.GetInstanceResponse) -> Op
81
119
  state.failureDetails.stackTrace.value if not helpers.is_empty(state.failureDetails.stackTrace) else None)
82
120
 
83
121
  return OrchestrationState(
84
- instance_id,
122
+ state.instanceId,
85
123
  state.name,
86
124
  OrchestrationStatus(state.orchestrationStatus),
87
125
  state.createdTimestamp.ToDatetime(),
@@ -93,7 +131,6 @@ def new_orchestration_state(instance_id: str, res: pb.GetInstanceResponse) -> Op
93
131
 
94
132
 
95
133
  class TaskHubGrpcClient:
96
-
97
134
  def __init__(self, *,
98
135
  host_address: Optional[str] = None,
99
136
  metadata: Optional[list[tuple[str, str]]] = None,
@@ -136,7 +173,7 @@ class TaskHubGrpcClient:
136
173
  req = pb.CreateInstanceRequest(
137
174
  name=name,
138
175
  instanceId=instance_id if instance_id else uuid.uuid4().hex,
139
- input=wrappers_pb2.StringValue(value=shared.to_json(input)) if input is not None else None,
176
+ input=helpers.get_string_value(shared.to_json(input) if input is not None else None),
140
177
  scheduledStartTimestamp=helpers.new_timestamp(start_at) if start_at else None,
141
178
  version=helpers.get_string_value(version if version else self.default_version),
142
179
  orchestrationIdReusePolicy=reuse_id_policy,
@@ -152,6 +189,42 @@ class TaskHubGrpcClient:
152
189
  res: pb.GetInstanceResponse = self._stub.GetInstance(req)
153
190
  return new_orchestration_state(req.instanceId, res)
154
191
 
192
+ def get_all_orchestration_states(self,
193
+ orchestration_query: Optional[OrchestrationQuery] = None
194
+ ) -> List[OrchestrationState]:
195
+ if orchestration_query is None:
196
+ orchestration_query = OrchestrationQuery()
197
+ _continuation_token = None
198
+
199
+ self._logger.info(f"Querying orchestration instances with query: {orchestration_query}")
200
+
201
+ states = []
202
+
203
+ while True:
204
+ req = pb.QueryInstancesRequest(
205
+ query=pb.InstanceQuery(
206
+ runtimeStatus=[status.value for status in orchestration_query.runtime_status] if orchestration_query.runtime_status else None,
207
+ createdTimeFrom=helpers.new_timestamp(orchestration_query.created_time_from) if orchestration_query.created_time_from else None,
208
+ createdTimeTo=helpers.new_timestamp(orchestration_query.created_time_to) if orchestration_query.created_time_to else None,
209
+ maxInstanceCount=orchestration_query.max_instance_count,
210
+ fetchInputsAndOutputs=orchestration_query.fetch_inputs_and_outputs,
211
+ continuationToken=_continuation_token
212
+ )
213
+ )
214
+ resp: pb.QueryInstancesResponse = self._stub.QueryInstances(req)
215
+ states += [parse_orchestration_state(res) for res in resp.orchestrationState]
216
+ # Check the value for continuationToken - none or "0" indicates that there are no more results.
217
+ if resp.continuationToken and resp.continuationToken.value and resp.continuationToken.value != "0":
218
+ self._logger.info(f"Received continuation token with value {resp.continuationToken.value}, fetching next list of instances...")
219
+ if _continuation_token and _continuation_token.value and _continuation_token.value == resp.continuationToken.value:
220
+ self._logger.warning(f"Received the same continuation token value {resp.continuationToken.value} again, stopping to avoid infinite loop.")
221
+ break
222
+ _continuation_token = resp.continuationToken
223
+ else:
224
+ break
225
+
226
+ return states
227
+
155
228
  def wait_for_orchestration_start(self, instance_id: str, *,
156
229
  fetch_payloads: bool = False,
157
230
  timeout: int = 60) -> Optional[OrchestrationState]:
@@ -199,7 +272,8 @@ class TaskHubGrpcClient:
199
272
  req = pb.RaiseEventRequest(
200
273
  instanceId=instance_id,
201
274
  name=event_name,
202
- input=wrappers_pb2.StringValue(value=shared.to_json(data)) if data else None)
275
+ input=helpers.get_string_value(shared.to_json(data) if data is not None else None)
276
+ )
203
277
 
204
278
  self._logger.info(f"Raising event '{event_name}' for instance '{instance_id}'.")
205
279
  self._stub.RaiseEvent(req)
@@ -209,7 +283,7 @@ class TaskHubGrpcClient:
209
283
  recursive: bool = True):
210
284
  req = pb.TerminateRequest(
211
285
  instanceId=instance_id,
212
- output=wrappers_pb2.StringValue(value=shared.to_json(output)) if output else None,
286
+ output=helpers.get_string_value(shared.to_json(output) if output is not None else None),
213
287
  recursive=recursive)
214
288
 
215
289
  self._logger.info(f"Terminating instance '{instance_id}'.")
@@ -225,10 +299,51 @@ class TaskHubGrpcClient:
225
299
  self._logger.info(f"Resuming instance '{instance_id}'.")
226
300
  self._stub.ResumeInstance(req)
227
301
 
228
- def purge_orchestration(self, instance_id: str, recursive: bool = True):
302
+ def restart_orchestration(self, instance_id: str, *,
303
+ restart_with_new_instance_id: bool = False) -> str:
304
+ """Restarts an existing orchestration instance.
305
+
306
+ Args:
307
+ instance_id: The ID of the orchestration instance to restart.
308
+ restart_with_new_instance_id: If True, the restarted orchestration will use a new instance ID.
309
+ If False (default), the restarted orchestration will reuse the same instance ID.
310
+
311
+ Returns:
312
+ The instance ID of the restarted orchestration.
313
+ """
314
+ req = pb.RestartInstanceRequest(
315
+ instanceId=instance_id,
316
+ restartWithNewInstanceId=restart_with_new_instance_id)
317
+
318
+ self._logger.info(f"Restarting instance '{instance_id}'.")
319
+ res: pb.RestartInstanceResponse = self._stub.RestartInstance(req)
320
+ return res.instanceId
321
+
322
+ def purge_orchestration(self, instance_id: str, recursive: bool = True) -> PurgeInstancesResult:
229
323
  req = pb.PurgeInstancesRequest(instanceId=instance_id, recursive=recursive)
230
324
  self._logger.info(f"Purging instance '{instance_id}'.")
231
- self._stub.PurgeInstances(req)
325
+ resp: pb.PurgeInstancesResponse = self._stub.PurgeInstances(req)
326
+ return PurgeInstancesResult(resp.deletedInstanceCount, resp.isComplete.value)
327
+
328
+ def purge_orchestrations_by(self,
329
+ created_time_from: Optional[datetime] = None,
330
+ created_time_to: Optional[datetime] = None,
331
+ runtime_status: Optional[List[OrchestrationStatus]] = None,
332
+ recursive: bool = False) -> PurgeInstancesResult:
333
+ self._logger.info("Purging orchestrations by filter: "
334
+ f"created_time_from={created_time_from}, "
335
+ f"created_time_to={created_time_to}, "
336
+ f"runtime_status={[str(status) for status in runtime_status] if runtime_status else None}, "
337
+ f"recursive={recursive}")
338
+ resp: pb.PurgeInstancesResponse = self._stub.PurgeInstances(pb.PurgeInstancesRequest(
339
+ purgeInstanceFilter=pb.PurgeInstanceFilter(
340
+ createdTimeFrom=helpers.new_timestamp(created_time_from) if created_time_from else None,
341
+ createdTimeTo=helpers.new_timestamp(created_time_to) if created_time_to else None,
342
+ runtimeStatus=[status.value for status in runtime_status] if runtime_status else None
343
+ ),
344
+ recursive=recursive
345
+ ))
346
+ return PurgeInstancesResult(resp.deletedInstanceCount, resp.isComplete.value)
232
347
 
233
348
  def signal_entity(self,
234
349
  entity_instance_id: EntityInstanceId,
@@ -237,7 +352,7 @@ class TaskHubGrpcClient:
237
352
  req = pb.SignalEntityRequest(
238
353
  instanceId=str(entity_instance_id),
239
354
  name=operation_name,
240
- input=wrappers_pb2.StringValue(value=shared.to_json(input)) if input else None,
355
+ input=helpers.get_string_value(shared.to_json(input) if input is not None else None),
241
356
  requestId=str(uuid.uuid4()),
242
357
  scheduledTime=None,
243
358
  parentTraceContext=None,
@@ -256,4 +371,69 @@ class TaskHubGrpcClient:
256
371
  if not res.exists:
257
372
  return None
258
373
 
259
- return EntityMetadata.from_entity_response(res, include_state)
374
+ return EntityMetadata.from_entity_metadata(res.entity, include_state)
375
+
376
+ def get_all_entities(self,
377
+ entity_query: Optional[EntityQuery] = None) -> List[EntityMetadata]:
378
+ if entity_query is None:
379
+ entity_query = EntityQuery()
380
+ _continuation_token = None
381
+
382
+ self._logger.info(f"Retrieving entities by filter: {entity_query}")
383
+
384
+ entities = []
385
+
386
+ while True:
387
+ query_request = pb.QueryEntitiesRequest(
388
+ query=pb.EntityQuery(
389
+ instanceIdStartsWith=helpers.get_string_value(entity_query.instance_id_starts_with),
390
+ lastModifiedFrom=helpers.new_timestamp(entity_query.last_modified_from) if entity_query.last_modified_from else None,
391
+ lastModifiedTo=helpers.new_timestamp(entity_query.last_modified_to) if entity_query.last_modified_to else None,
392
+ includeState=entity_query.include_state,
393
+ includeTransient=entity_query.include_transient,
394
+ pageSize=helpers.get_int_value(entity_query.page_size),
395
+ continuationToken=_continuation_token
396
+ )
397
+ )
398
+ resp: pb.QueryEntitiesResponse = self._stub.QueryEntities(query_request)
399
+ entities += [EntityMetadata.from_entity_metadata(entity, query_request.query.includeState) for entity in resp.entities]
400
+ if resp.continuationToken and resp.continuationToken.value and resp.continuationToken.value != "0":
401
+ self._logger.info(f"Received continuation token with value {resp.continuationToken.value}, fetching next page of entities...")
402
+ if _continuation_token and _continuation_token.value and _continuation_token.value == resp.continuationToken.value:
403
+ self._logger.warning(f"Received the same continuation token value {resp.continuationToken.value} again, stopping to avoid infinite loop.")
404
+ break
405
+ _continuation_token = resp.continuationToken
406
+ else:
407
+ break
408
+ return entities
409
+
410
+ def clean_entity_storage(self,
411
+ remove_empty_entities: bool = True,
412
+ release_orphaned_locks: bool = True
413
+ ) -> CleanEntityStorageResult:
414
+ self._logger.info("Cleaning entity storage")
415
+
416
+ empty_entities_removed = 0
417
+ orphaned_locks_released = 0
418
+ _continuation_token = None
419
+
420
+ while True:
421
+ req = pb.CleanEntityStorageRequest(
422
+ removeEmptyEntities=remove_empty_entities,
423
+ releaseOrphanedLocks=release_orphaned_locks,
424
+ continuationToken=_continuation_token
425
+ )
426
+ resp: pb.CleanEntityStorageResponse = self._stub.CleanEntityStorage(req)
427
+ empty_entities_removed += resp.emptyEntitiesRemoved
428
+ orphaned_locks_released += resp.orphanedLocksReleased
429
+
430
+ if resp.continuationToken and resp.continuationToken.value and resp.continuationToken.value != "0":
431
+ self._logger.info(f"Received continuation token with value {resp.continuationToken.value}, cleaning next page...")
432
+ if _continuation_token and _continuation_token.value and _continuation_token.value == resp.continuationToken.value:
433
+ self._logger.warning(f"Received the same continuation token value {resp.continuationToken.value} again, stopping to avoid infinite loop.")
434
+ break
435
+ _continuation_token = resp.continuationToken
436
+ else:
437
+ break
438
+
439
+ return CleanEntityStorageResult(empty_entities_removed, orphaned_locks_released)
@@ -8,7 +8,9 @@ from durabletask.entities.durable_entity import DurableEntity
8
8
  from durabletask.entities.entity_lock import EntityLock
9
9
  from durabletask.entities.entity_context import EntityContext
10
10
  from durabletask.entities.entity_metadata import EntityMetadata
11
+ from durabletask.entities.entity_operation_failed_exception import EntityOperationFailedException
11
12
 
12
- __all__ = ["EntityInstanceId", "DurableEntity", "EntityLock", "EntityContext", "EntityMetadata"]
13
+ __all__ = ["EntityInstanceId", "DurableEntity", "EntityLock", "EntityContext", "EntityMetadata",
14
+ "EntityOperationFailedException"]
13
15
 
14
16
  PACKAGE_NAME = "durabletask.entities"
@@ -0,0 +1,84 @@
1
+ class EntityInstanceId:
2
+ def __init__(self, entity: str, key: str):
3
+ EntityInstanceId.validate_entity_name(entity)
4
+ EntityInstanceId.validate_key(key)
5
+ self.entity = entity.lower()
6
+ self.key = key
7
+
8
+ def __str__(self) -> str:
9
+ return f"@{self.entity}@{self.key}"
10
+
11
+ def __eq__(self, other):
12
+ if not isinstance(other, EntityInstanceId):
13
+ return False
14
+ return self.entity == other.entity and self.key == other.key
15
+
16
+ def __lt__(self, other):
17
+ if not isinstance(other, EntityInstanceId):
18
+ return self < other
19
+ return str(self) < str(other)
20
+
21
+ @staticmethod
22
+ def parse(entity_id: str) -> "EntityInstanceId":
23
+ """Parse a string representation of an entity ID into an EntityInstanceId object.
24
+
25
+ Parameters
26
+ ----------
27
+ entity_id : str
28
+ The string representation of the entity ID, in the format '@entity@key'.
29
+
30
+ Returns
31
+ -------
32
+ EntityInstanceId
33
+ The parsed EntityInstanceId object.
34
+
35
+ Raises
36
+ ------
37
+ ValueError
38
+ If the input string is not in the correct format.
39
+ """
40
+ if not entity_id.startswith("@"):
41
+ raise ValueError("Entity ID must start with '@'.")
42
+ try:
43
+ _, entity, key = entity_id.split("@", 2)
44
+ except ValueError as ex:
45
+ raise ValueError(f"Invalid entity ID format: {entity_id}") from ex
46
+ return EntityInstanceId(entity=entity, key=key)
47
+
48
+ @staticmethod
49
+ def validate_entity_name(name: str) -> None:
50
+ """Validate that the entity name does not contain invalid characters.
51
+
52
+ Parameters
53
+ ----------
54
+ name : str
55
+ The entity name to validate.
56
+
57
+ Raises
58
+ ------
59
+ ValueError
60
+ If the name is not a valid entity name.
61
+ """
62
+ if not name:
63
+ raise ValueError("Entity name cannot be empty.")
64
+ if "@" in name:
65
+ raise ValueError("Entity name cannot contain '@' symbol.")
66
+
67
+ @staticmethod
68
+ def validate_key(key: str) -> None:
69
+ """Validate that the entity key does not contain invalid characters.
70
+
71
+ Parameters
72
+ ----------
73
+ key : str
74
+ The entity key to validate.
75
+
76
+ Raises
77
+ ------
78
+ ValueError
79
+ If the key is not a valid entity key.
80
+ """
81
+ if not key:
82
+ raise ValueError("Entity key cannot be empty.")
83
+ if "@" in key:
84
+ raise ValueError("Entity key cannot contain '@' symbol.")
@@ -44,18 +44,22 @@ class EntityMetadata:
44
44
 
45
45
  @staticmethod
46
46
  def from_entity_response(entity_response: pb.GetEntityResponse, includes_state: bool):
47
+ return EntityMetadata.from_entity_metadata(entity_response.entity, includes_state)
48
+
49
+ @staticmethod
50
+ def from_entity_metadata(entity: pb.EntityMetadata, includes_state: bool):
47
51
  try:
48
- entity_id = EntityInstanceId.parse(entity_response.entity.instanceId)
52
+ entity_id = EntityInstanceId.parse(entity.instanceId)
49
53
  except ValueError:
50
54
  raise ValueError("Invalid entity instance ID in entity response.")
51
55
  entity_state = None
52
56
  if includes_state:
53
- entity_state = entity_response.entity.serializedState.value
57
+ entity_state = entity.serializedState.value
54
58
  return EntityMetadata(
55
59
  id=entity_id,
56
- last_modified=entity_response.entity.lastModifiedTime.ToDatetime(timezone.utc),
57
- backlog_queue_size=entity_response.entity.backlogQueueSize,
58
- locked_by=entity_response.entity.lockedBy.value,
60
+ last_modified=entity.lastModifiedTime.ToDatetime(timezone.utc),
61
+ backlog_queue_size=entity.backlogQueueSize,
62
+ locked_by=entity.lockedBy.value,
59
63
  includes_state=includes_state,
60
64
  state=entity_state
61
65
  )
@@ -0,0 +1,15 @@
1
+ from durabletask.internal.orchestrator_service_pb2 import TaskFailureDetails
2
+ from durabletask.entities.entity_instance_id import EntityInstanceId
3
+
4
+
5
+ class EntityOperationFailedException(Exception):
6
+ """Exception raised when an operation on an Entity Function fails."""
7
+
8
+ def __init__(self, entity_instance_id: EntityInstanceId, operation_name: str, failure_details: TaskFailureDetails) -> None:
9
+ super().__init__()
10
+ self.entity_instance_id = entity_instance_id
11
+ self.operation_name = operation_name
12
+ self.failure_details = failure_details
13
+
14
+ def __str__(self) -> str:
15
+ return f"Operation '{self.operation_name}' on entity '{self.entity_instance_id}' failed with error: {self.failure_details.errorMessage}"
@@ -184,6 +184,13 @@ def get_string_value(val: Optional[str]) -> Optional[wrappers_pb2.StringValue]:
184
184
  return wrappers_pb2.StringValue(value=val)
185
185
 
186
186
 
187
+ def get_int_value(val: Optional[int]) -> Optional[wrappers_pb2.Int32Value]:
188
+ if val is None:
189
+ return None
190
+ else:
191
+ return wrappers_pb2.Int32Value(value=val)
192
+
193
+
187
194
  def get_string_value_or_empty(val: Optional[str]) -> wrappers_pb2.StringValue:
188
195
  if val is None:
189
196
  return wrappers_pb2.StringValue(value="")
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+
4
+ class JsonEncodeOutputException(Exception):
5
+ """Custom exception type used to indicate that an orchestration result could not be JSON-encoded."""
6
+
7
+ def __init__(self, problem_object: Any):
8
+ super().__init__()
9
+ self.problem_object = problem_object
10
+
11
+ def __str__(self) -> str:
12
+ return f"The orchestration result could not be encoded. Object details: {self.problem_object}"