|
3 | 3 | import json |
4 | 4 | from dataclasses import replace |
5 | 5 | from datetime import UTC, datetime |
6 | | -from typing import TYPE_CHECKING |
| 6 | +from typing import TYPE_CHECKING, Any |
7 | 7 | from uuid import uuid4 |
8 | 8 |
|
9 | 9 | from aws_durable_execution_sdk_python.execution import ( |
10 | 10 | DurableExecutionInvocationOutput, |
11 | 11 | InvocationStatus, |
12 | 12 | ) |
13 | 13 | from aws_durable_execution_sdk_python.lambda_service import ( |
| 14 | + CallbackOptions, |
| 15 | + ContextOptions, |
14 | 16 | ErrorObject, |
15 | 17 | ExecutionDetails, |
| 18 | + InvokeOptions, |
16 | 19 | Operation, |
| 20 | + OperationAction, |
17 | 21 | OperationStatus, |
| 22 | + OperationSubType, |
18 | 23 | OperationType, |
19 | 24 | OperationUpdate, |
| 25 | + StepOptions, |
| 26 | + WaitOptions, |
20 | 27 | ) |
21 | 28 |
|
22 | 29 | # Import AWS exceptions |
|
27 | 34 | from aws_durable_execution_sdk_python_testing.token import CheckpointToken |
28 | 35 |
|
29 | 36 |
|
| 37 | +def _operation_update_from_dict(data: dict[str, Any]) -> OperationUpdate: |
| 38 | + """Create OperationUpdate from dictionary data.""" |
| 39 | + error = ErrorObject.from_dict(data["Error"]) if data.get("Error") else None |
| 40 | + |
| 41 | + context_options = None |
| 42 | + if context_data := data.get("ContextOptions"): |
| 43 | + context_options = ContextOptions( |
| 44 | + replay_children=context_data.get("ReplayChildren", False) |
| 45 | + ) |
| 46 | + |
| 47 | + step_options = None |
| 48 | + if step_data := data.get("StepOptions"): |
| 49 | + step_options = StepOptions( |
| 50 | + next_attempt_delay_seconds=step_data.get("NextAttemptDelaySeconds") |
| 51 | + ) |
| 52 | + |
| 53 | + wait_options = None |
| 54 | + if wait_data := data.get("WaitOptions"): |
| 55 | + wait_options = WaitOptions.from_dict(wait_data) |
| 56 | + |
| 57 | + callback_options = None |
| 58 | + if callback_data := data.get("CallbackOptions"): |
| 59 | + callback_options = CallbackOptions.from_dict(callback_data) |
| 60 | + |
| 61 | + invoke_options = None |
| 62 | + if invoke_data := data.get("InvokeOptions"): |
| 63 | + invoke_options = InvokeOptions( |
| 64 | + function_name=invoke_data.get("FunctionName", ""), |
| 65 | + timeout_seconds=invoke_data.get("TimeoutSeconds"), |
| 66 | + ) |
| 67 | + |
| 68 | + return OperationUpdate( |
| 69 | + operation_id=data["Id"], |
| 70 | + operation_type=OperationType(data["Type"]), |
| 71 | + action=OperationAction(data["Action"]), |
| 72 | + parent_id=data.get("ParentId"), |
| 73 | + name=data.get("Name"), |
| 74 | + sub_type=OperationSubType(data["SubType"]) if data.get("SubType") else None, |
| 75 | + payload=data.get("Payload"), |
| 76 | + error=error, |
| 77 | + context_options=context_options, |
| 78 | + step_options=step_options, |
| 79 | + wait_options=wait_options, |
| 80 | + callback_options=callback_options, |
| 81 | + invoke_options=invoke_options, |
| 82 | + ) |
| 83 | + |
| 84 | + |
30 | 85 | if TYPE_CHECKING: |
31 | 86 | from aws_durable_execution_sdk_python_testing.model import ( |
32 | 87 | StartDurableExecutionInput, |
|
0 commit comments