-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodel.py
More file actions
3296 lines (2818 loc) · 118 KB
/
model.py
File metadata and controls
3296 lines (2818 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Model classes for the web API."""
from __future__ import annotations
import datetime
import json
from dataclasses import dataclass, replace
from enum import Enum
from typing import Any
from aws_durable_execution_sdk_python.execution import DurableExecutionInvocationOutput
# Import existing types from the main SDK - REUSE EVERYTHING POSSIBLE
from aws_durable_execution_sdk_python.lambda_service import (
CallbackDetails,
CallbackOptions,
ChainedInvokeDetails,
ChainedInvokeOptions,
ContextDetails,
ContextOptions,
ErrorObject,
ExecutionDetails,
Operation,
OperationAction,
OperationStatus,
OperationSubType,
OperationType,
OperationUpdate,
StepDetails,
StepOptions,
TimestampConverter,
WaitDetails,
WaitOptions,
)
from aws_durable_execution_sdk_python.types import (
LambdaContext as LambdaContextProtocol,
)
from dateutil.tz import UTC
from aws_durable_execution_sdk_python_testing.exceptions import (
InvalidParameterValueException,
)
class EventType(Enum):
"""Event types for durable execution events."""
EXECUTION_STARTED = "ExecutionStarted"
EXECUTION_SUCCEEDED = "ExecutionSucceeded"
EXECUTION_FAILED = "ExecutionFailed"
EXECUTION_TIMED_OUT = "ExecutionTimedOut"
EXECUTION_STOPPED = "ExecutionStopped"
CONTEXT_STARTED = "ContextStarted"
CONTEXT_SUCCEEDED = "ContextSucceeded"
CONTEXT_FAILED = "ContextFailed"
WAIT_STARTED = "WaitStarted"
WAIT_SUCCEEDED = "WaitSucceeded"
WAIT_CANCELLED = "WaitCancelled"
STEP_STARTED = "StepStarted"
STEP_SUCCEEDED = "StepSucceeded"
STEP_FAILED = "StepFailed"
CHAINED_INVOKE_STARTED = "ChainedInvokeStarted"
CHAINED_INVOKE_SUCCEEDED = "ChainedInvokeSucceeded"
CHAINED_INVOKE_FAILED = "ChainedInvokeFailed"
CHAINED_INVOKE_TIMED_OUT = "ChainedInvokeTimedOut"
CHAINED_INVOKE_STOPPED = "ChainedInvokeStopped"
CALLBACK_STARTED = "CallbackStarted"
CALLBACK_SUCCEEDED = "CallbackSucceeded"
CALLBACK_FAILED = "CallbackFailed"
CALLBACK_TIMED_OUT = "CallbackTimedOut"
INVOCATION_COMPLETED = "InvocationCompleted"
TERMINAL_STATUSES: set[OperationStatus] = {
OperationStatus.SUCCEEDED,
OperationStatus.FAILED,
OperationStatus.TIMED_OUT,
OperationStatus.STOPPED,
OperationStatus.CANCELLED,
}
@dataclass(frozen=True)
class LambdaContext(LambdaContextProtocol):
"""Lambda context for testing."""
aws_request_id: str
log_group_name: str | None = None
log_stream_name: str | None = None
function_name: str | None = None
memory_limit_in_mb: str | None = None
function_version: str | None = None
invoked_function_arn: str | None = None
tenant_id: str | None = None
client_context: dict | None = None
identity: dict | None = None
def get_remaining_time_in_millis(self) -> int:
return 900000 # 15 minutes default
def log(self, msg) -> None:
pass # No-op for testing
# region web_api_models
# Web API specific models (not in Smithy but needed for web interface)
@dataclass(frozen=True)
class StartDurableExecutionInput:
"""Input for starting a durable execution via web API."""
account_id: str
function_name: str
function_qualifier: str
execution_name: str
execution_timeout_seconds: int
execution_retention_period_days: int
invocation_id: str | None = None
trace_fields: dict | None = None
tenant_id: str | None = None
input: str | None = None
lambda_endpoint: str | None = None # Endpoint for this specific execution
@classmethod
def from_dict(cls, data: dict) -> StartDurableExecutionInput:
# Validate required fields and raise AWS-compliant exceptions
required_fields = [
"AccountId",
"FunctionName",
"FunctionQualifier",
"ExecutionName",
"ExecutionTimeoutSeconds",
"ExecutionRetentionPeriodDays",
]
for field in required_fields:
if field not in data:
msg: str = f"Missing required field: {field}"
raise InvalidParameterValueException(msg)
return cls(
account_id=data["AccountId"],
function_name=data["FunctionName"],
function_qualifier=data["FunctionQualifier"],
execution_name=data["ExecutionName"],
execution_timeout_seconds=data["ExecutionTimeoutSeconds"],
execution_retention_period_days=data["ExecutionRetentionPeriodDays"],
invocation_id=data.get("InvocationId"),
trace_fields=data.get("TraceFields"),
tenant_id=data.get("TenantId"),
input=data.get("Input"),
lambda_endpoint=data.get("LambdaEndpoint", None),
)
def to_dict(self) -> dict[str, Any]:
result = {
"AccountId": self.account_id,
"FunctionName": self.function_name,
"FunctionQualifier": self.function_qualifier,
"ExecutionName": self.execution_name,
"ExecutionTimeoutSeconds": self.execution_timeout_seconds,
"ExecutionRetentionPeriodDays": self.execution_retention_period_days,
}
if self.invocation_id is not None:
result["InvocationId"] = self.invocation_id
if self.trace_fields is not None:
result["TraceFields"] = self.trace_fields
if self.tenant_id is not None:
result["TenantId"] = self.tenant_id
if self.input is not None:
result["Input"] = self.input
if self.lambda_endpoint is not None:
result["LambdaEndpoint"] = self.lambda_endpoint
return result
def get_normalized_input(self):
"""
Normalize input string to be JSON deserializable.
Avoid double coding json input.
"""
# Try to parse once
try:
_ = json.loads(self.input)
return self.input
except (json.JSONDecodeError, TypeError):
# Not valid JSON, treat as plain string and encode it
return json.dumps(self.input)
@dataclass(frozen=True)
class StartDurableExecutionOutput:
"""Output from starting a durable execution via web API."""
execution_arn: str | None = None
@classmethod
def from_dict(cls, data: dict) -> StartDurableExecutionOutput:
return cls(execution_arn=data.get("ExecutionArn"))
def to_dict(self) -> dict[str, Any]:
result = {}
if self.execution_arn is not None:
result["ExecutionArn"] = self.execution_arn
return result
# endregion web_api_models
# region smithy_api_models
# Smithy-based API models
@dataclass(frozen=True)
class GetDurableExecutionRequest:
"""Request to get durable execution details."""
durable_execution_arn: str
@classmethod
def from_dict(cls, data: dict) -> GetDurableExecutionRequest:
return cls(durable_execution_arn=data["DurableExecutionArn"])
def to_dict(self) -> dict[str, Any]:
return {"DurableExecutionArn": self.durable_execution_arn}
@dataclass(frozen=True)
class GetDurableExecutionResponse:
"""Response containing durable execution details."""
durable_execution_arn: str
durable_execution_name: str
function_arn: str
status: str
start_timestamp: datetime.datetime
input_payload: str | None = None
result: str | None = None
error: ErrorObject | None = None
end_timestamp: datetime.datetime | None = None
version: str | None = None
@classmethod
def from_dict(cls, data: dict) -> GetDurableExecutionResponse:
error = None
if error_data := data.get("Error"):
error = ErrorObject.from_dict(error_data)
return cls(
durable_execution_arn=data["DurableExecutionArn"],
durable_execution_name=data["DurableExecutionName"],
function_arn=data["FunctionArn"],
status=data["Status"],
start_timestamp=data["StartTimestamp"],
input_payload=data.get("InputPayload"),
result=data.get("Result"),
error=error,
end_timestamp=data.get("EndTimestamp"),
version=data.get("Version"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {
"DurableExecutionArn": self.durable_execution_arn,
"DurableExecutionName": self.durable_execution_name,
"FunctionArn": self.function_arn,
"Status": self.status,
"StartTimestamp": self.start_timestamp,
}
if self.input_payload is not None:
result["InputPayload"] = self.input_payload
if self.result is not None:
result["Result"] = self.result
if self.error is not None:
result["Error"] = self.error.to_dict()
if self.end_timestamp is not None:
result["EndTimestamp"] = self.end_timestamp
if self.end_timestamp is not None:
result["EndTimestamp"] = self.end_timestamp
if self.version is not None:
result["Version"] = self.version
return result
@dataclass(frozen=True)
class Execution:
"""Execution summary structure from Smithy model."""
durable_execution_arn: str
durable_execution_name: str
function_arn: str
status: str
start_timestamp: datetime.datetime
end_timestamp: datetime.datetime | None = None
@classmethod
def from_dict(cls, data: dict) -> Execution:
return cls(
durable_execution_arn=data["DurableExecutionArn"],
durable_execution_name=data["DurableExecutionName"],
function_arn=data.get(
"FunctionArn", ""
), # Make optional for backward compatibility
status=data["Status"],
start_timestamp=data["StartTimestamp"],
end_timestamp=data.get("EndTimestamp"),
)
def to_dict(self) -> dict[str, Any]:
result = {
"DurableExecutionArn": self.durable_execution_arn,
"DurableExecutionName": self.durable_execution_name,
"Status": self.status,
"StartTimestamp": self.start_timestamp,
}
if self.function_arn: # Only include if not empty
result["FunctionArn"] = self.function_arn
if self.end_timestamp is not None:
result["EndTimestamp"] = self.end_timestamp
return result
@classmethod
def from_execution(cls, execution, status: str) -> Execution:
"""Create ExecutionSummary from Execution object."""
execution_op = execution.get_operation_execution_started()
return cls(
durable_execution_arn=execution.durable_execution_arn,
durable_execution_name=execution.start_input.execution_name,
function_arn=f"arn:aws:lambda:us-east-1:123456789012:function:{execution.start_input.function_name}",
status=status,
start_timestamp=execution_op.start_timestamp
if execution_op.start_timestamp
else datetime.datetime.now(datetime.UTC),
end_timestamp=execution_op.end_timestamp
if execution_op.end_timestamp
else None,
)
@dataclass(frozen=True)
class ListDurableExecutionsRequest:
"""Request to list durable executions."""
function_name: str | None = None
function_version: str | None = None
durable_execution_name: str | None = None
status_filter: list[str] | None = None
started_after: str | None = None
started_before: str | None = None
marker: str | None = None
max_items: int = 0
reverse_order: bool | None = None
@classmethod
def from_dict(cls, data: dict) -> ListDurableExecutionsRequest:
# Handle query parameters that may be lists
function_name = data.get("FunctionName")
if isinstance(function_name, list):
function_name = function_name[0] if function_name else None
function_version = data.get("FunctionVersion")
if isinstance(function_version, list):
function_version = function_version[0] if function_version else None
durable_execution_name = data.get("DurableExecutionName")
if isinstance(durable_execution_name, list):
durable_execution_name = (
durable_execution_name[0] if durable_execution_name else None
)
status_filter = data.get("StatusFilter")
if isinstance(status_filter, list):
status_filter = status_filter if status_filter else None
elif status_filter:
status_filter = [status_filter]
started_after = data.get("StartedAfter")
if isinstance(started_after, list):
started_after = started_after[0] if started_after else None
started_before = data.get("StartedBefore")
if isinstance(started_before, list):
started_before = started_before[0] if started_before else None
marker = data.get("Marker")
if isinstance(marker, list):
marker = marker[0] if marker else None
max_items = data.get("MaxItems", 0)
if isinstance(max_items, list):
max_items = int(max_items[0]) if max_items else 0
reverse_order = data.get("ReverseOrder")
if isinstance(reverse_order, list):
reverse_order = (
reverse_order[0].lower() in ("true", "1", "yes")
if reverse_order
else None
)
elif isinstance(reverse_order, str):
reverse_order = reverse_order.lower() in ("true", "1", "yes")
return cls(
function_name=function_name,
function_version=function_version,
durable_execution_name=durable_execution_name,
status_filter=status_filter,
started_after=started_after,
started_before=started_before,
marker=marker,
max_items=max_items,
reverse_order=reverse_order,
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.function_name is not None:
result["FunctionName"] = self.function_name
if self.function_version is not None:
result["FunctionVersion"] = self.function_version
if self.durable_execution_name is not None:
result["DurableExecutionName"] = self.durable_execution_name
if self.status_filter is not None:
result["StatusFilter"] = self.status_filter
if self.started_after is not None:
result["StartedAfter"] = self.started_after
if self.started_before is not None:
result["StartedBefore"] = self.started_before
if self.marker is not None:
result["Marker"] = self.marker
if self.max_items is not None:
result["MaxItems"] = self.max_items
if self.reverse_order is not None:
result["ReverseOrder"] = self.reverse_order
return result
@dataclass(frozen=True)
class ListDurableExecutionsResponse:
"""Response containing list of durable executions."""
durable_executions: list[Execution]
next_marker: str | None = None
@classmethod
def from_dict(cls, data: dict) -> ListDurableExecutionsResponse:
executions = [
Execution.from_dict(exec_data)
for exec_data in data.get("DurableExecutions", [])
]
return cls(
durable_executions=executions,
next_marker=data.get("NextMarker"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {
"DurableExecutions": [exe.to_dict() for exe in self.durable_executions]
}
if self.next_marker is not None:
result["NextMarker"] = self.next_marker
return result
@dataclass(frozen=True)
class StopDurableExecutionRequest:
"""Request to stop a durable execution."""
durable_execution_arn: str
error: ErrorObject | None = None
@classmethod
def from_dict(cls, data: dict) -> StopDurableExecutionRequest:
error = None
if error_data := data.get("Error"):
error = ErrorObject.from_dict(error_data)
return cls(
durable_execution_arn=data["DurableExecutionArn"],
error=error,
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {"DurableExecutionArn": self.durable_execution_arn}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class StopDurableExecutionResponse:
"""Response from stopping a durable execution."""
stop_timestamp: datetime.datetime
@classmethod
def from_dict(cls, data: dict) -> StopDurableExecutionResponse:
return cls(stop_timestamp=data["StopTimestamp"])
def to_dict(self) -> dict[str, Any]:
return {"StopTimestamp": self.stop_timestamp}
@dataclass(frozen=True)
class GetDurableExecutionStateRequest:
"""Request to get durable execution state."""
durable_execution_arn: str
checkpoint_token: str
marker: str | None = None
max_items: int = 0
@classmethod
def from_dict(cls, data: dict) -> GetDurableExecutionStateRequest:
return cls(
durable_execution_arn=data["DurableExecutionArn"],
checkpoint_token=data["CheckpointToken"],
marker=data.get("Marker"),
max_items=data.get("MaxItems", 0),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {
"DurableExecutionArn": self.durable_execution_arn,
"CheckpointToken": self.checkpoint_token,
}
if self.marker is not None:
result["Marker"] = self.marker
if self.max_items is not None:
result["MaxItems"] = self.max_items
return result
@dataclass(frozen=True)
class GetDurableExecutionStateResponse:
"""Response containing durable execution state operations."""
operations: list[Operation]
next_marker: str | None = None
@classmethod
def from_dict(cls, data: dict) -> GetDurableExecutionStateResponse:
operations = [
Operation.from_dict(op_data) for op_data in data.get("Operations", [])
]
return cls(
operations=operations,
next_marker=data.get("NextMarker"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {
"Operations": [op.to_dict() for op in self.operations]
}
if self.next_marker is not None:
result["NextMarker"] = self.next_marker
return result
# endregion smithy_api_models
# region event_structures
# Event-related structures from Smithy model
@dataclass(frozen=True)
class EventInput:
"""Event input structure."""
payload: str | None = None
truncated: bool = False
@classmethod
def from_dict(cls, data: dict) -> EventInput:
return cls(
payload=data.get("Payload"),
truncated=data.get("Truncated", False),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {"Truncated": self.truncated}
if self.payload is not None:
result["Payload"] = self.payload
return result
@classmethod
def from_details(
cls,
details: ExecutionDetails,
include: bool = False, # noqa: FBT001, FBT002
) -> EventInput:
details_input: str | None = details.input_payload if details else None
payload: str | None = details_input if include else None
truncated: bool = not include
return cls(payload=payload, truncated=truncated)
@classmethod
def from_start_durable_execution_input(
cls,
start_durable_execution_input: StartDurableExecutionInput,
include: bool = False, # noqa: FBT001, FBT002
) -> EventInput:
input: str | None = start_durable_execution_input.input
truncated: bool = not include
return cls(input, truncated)
@dataclass(frozen=True)
class EventResult:
"""Event result structure."""
payload: str | None = None
truncated: bool = False
@classmethod
def from_dict(cls, data: dict) -> EventResult:
return cls(
payload=data.get("Payload"),
truncated=data.get("Truncated", False),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {"Truncated": self.truncated}
if self.payload is not None:
result["Payload"] = self.payload
return result
@classmethod
def from_details(
cls,
details: CallbackDetails | StepDetails | ChainedInvokeDetails | ContextDetails,
include: bool = False, # noqa: FBT001, FBT002
) -> EventResult:
details_result: str | None = details.result if details else None
payload: str | None = details_result if include else None
truncated: bool = not include
return cls(payload=payload, truncated=truncated)
@classmethod
def from_durable_execution_invocation_output(
cls,
durable_execution_invocation_output: DurableExecutionInvocationOutput,
include: bool = False, # noqa: FBT001, FBT002
) -> EventResult:
truncated: bool = not include
return cls(durable_execution_invocation_output.result, truncated)
@dataclass(frozen=True)
class EventError:
"""Event error structure."""
payload: ErrorObject | None = None
truncated: bool = False
@classmethod
def from_dict(cls, data: dict) -> EventError:
payload = None
if payload_data := data.get("Payload"):
payload = ErrorObject.from_dict(payload_data)
return cls(
payload=payload,
truncated=data.get("Truncated", False),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {"Truncated": self.truncated}
if self.payload is not None:
result["Payload"] = self.payload.to_dict()
return result
@classmethod
def from_details(
cls,
details: CallbackDetails | StepDetails | ChainedInvokeDetails | ContextDetails,
include: bool = False, # noqa: FBT001, FBT002
) -> EventError:
error_object: ErrorObject | None = details.error if details else None
truncated: bool = not include
return cls(error_object, truncated)
@classmethod
def from_durable_execution_invocation_output(
cls,
durable_execution_invocation_output: DurableExecutionInvocationOutput,
include: bool = False, # noqa: FBT001, FBT002
) -> EventError:
truncated: bool = not include
return cls(durable_execution_invocation_output.error, truncated)
@dataclass(frozen=True)
class RetryDetails:
"""Retry details structure."""
current_attempt: int = 0
next_attempt_delay_seconds: int | None = None
@classmethod
def from_dict(cls, data: dict) -> RetryDetails:
return cls(
current_attempt=data.get("CurrentAttempt", 0),
next_attempt_delay_seconds=data.get("NextAttemptDelaySeconds"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {"CurrentAttempt": self.current_attempt}
if self.next_attempt_delay_seconds is not None:
result["NextAttemptDelaySeconds"] = self.next_attempt_delay_seconds
return result
# Event detail structures
@dataclass(frozen=True)
class ExecutionStartedDetails:
"""Execution started event details."""
input: EventInput | None = None
execution_timeout: int | None = None
@classmethod
def from_dict(cls, data: dict) -> ExecutionStartedDetails:
input_data = None
if input_dict := data.get("Input"):
input_data = EventInput.from_dict(input_dict)
return cls(
input=input_data,
execution_timeout=data.get("ExecutionTimeout"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.input is not None:
result["Input"] = self.input.to_dict()
if self.execution_timeout is not None:
result["ExecutionTimeout"] = self.execution_timeout
return result
@dataclass(frozen=True)
class ExecutionSucceededDetails:
"""Execution succeeded event details."""
result: EventResult | None = None
@classmethod
def from_dict(cls, data: dict) -> ExecutionSucceededDetails:
result_data = None
if result_dict := data.get("Result"):
result_data = EventResult.from_dict(result_dict)
return cls(result=result_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.result is not None:
result["Result"] = self.result.to_dict()
return result
@dataclass(frozen=True)
class ExecutionFailedDetails:
"""Execution failed event details."""
error: EventError | None = None
@classmethod
def from_dict(cls, data: dict) -> ExecutionFailedDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
return cls(error=error_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class ExecutionTimedOutDetails:
"""Execution timed out event details."""
error: EventError | None = None
@classmethod
def from_dict(cls, data: dict) -> ExecutionTimedOutDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
return cls(error=error_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class ExecutionStoppedDetails:
"""Execution stopped event details."""
error: EventError | None = None
@classmethod
def from_dict(cls, data: dict) -> ExecutionStoppedDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
return cls(error=error_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class ContextStartedDetails:
"""Context started event details."""
@classmethod
def from_dict(cls, data: dict) -> ContextStartedDetails: # noqa: ARG003
return cls()
def to_dict(self) -> dict[str, Any]:
return {}
@dataclass(frozen=True)
class ContextSucceededDetails:
"""Context succeeded event details."""
result: EventResult | None = None
@classmethod
def from_dict(cls, data: dict) -> ContextSucceededDetails:
result_data = None
if result_dict := data.get("Result"):
result_data = EventResult.from_dict(result_dict)
return cls(result=result_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.result is not None:
result["Result"] = self.result.to_dict()
return result
@dataclass(frozen=True)
class ContextFailedDetails:
"""Context failed event details."""
error: EventError | None = None
@classmethod
def from_dict(cls, data: dict) -> ContextFailedDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
return cls(error=error_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class WaitStartedDetails:
"""Wait started event details."""
duration: int | None = None
scheduled_end_timestamp: datetime.datetime | None = None
@classmethod
def from_dict(cls, data: dict) -> WaitStartedDetails:
return cls(
duration=data.get("Duration"),
scheduled_end_timestamp=data.get("ScheduledEndTimestamp"),
)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.duration is not None:
result["Duration"] = self.duration
if self.scheduled_end_timestamp is not None:
result["ScheduledEndTimestamp"] = self.scheduled_end_timestamp
return result
@dataclass(frozen=True)
class WaitSucceededDetails:
"""Wait succeeded event details."""
duration: int | None = None
@classmethod
def from_dict(cls, data: dict) -> WaitSucceededDetails:
return cls(duration=data.get("Duration"))
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.duration is not None:
result["Duration"] = self.duration
return result
@dataclass(frozen=True)
class WaitCancelledDetails:
"""Wait cancelled event details."""
error: EventError | None = None
@classmethod
def from_dict(cls, data: dict) -> WaitCancelledDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
return cls(error=error_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()
return result
@dataclass(frozen=True)
class StepStartedDetails:
"""Step started event details."""
@classmethod
def from_dict(cls, data: dict) -> StepStartedDetails: # noqa: ARG003
return cls()
def to_dict(self) -> dict[str, Any]:
return {}
@dataclass(frozen=True)
class StepSucceededDetails:
"""Step succeeded event details."""
result: EventResult | None = None
retry_details: RetryDetails | None = None
@classmethod
def from_dict(cls, data: dict) -> StepSucceededDetails:
result_data = None
if result_dict := data.get("Result"):
result_data = EventResult.from_dict(result_dict)
retry_details_data = None
if retry_dict := data.get("RetryDetails"):
retry_details_data = RetryDetails.from_dict(retry_dict)
return cls(result=result_data, retry_details=retry_details_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.result is not None:
result["Result"] = self.result.to_dict()
if self.retry_details is not None:
result["RetryDetails"] = self.retry_details.to_dict()
return result
@dataclass(frozen=True)
class StepFailedDetails:
"""Step failed event details."""
error: EventError | None = None
retry_details: RetryDetails | None = None
@classmethod
def from_dict(cls, data: dict) -> StepFailedDetails:
error_data = None
if error_dict := data.get("Error"):
error_data = EventError.from_dict(error_dict)
retry_details_data = None
if retry_dict := data.get("RetryDetails"):
retry_details_data = RetryDetails.from_dict(retry_dict)
return cls(error=error_data, retry_details=retry_details_data)
def to_dict(self) -> dict[str, Any]:
result: dict[str, Any] = {}
if self.error is not None:
result["Error"] = self.error.to_dict()