Skip to content

Commit 51e75aa

Browse files
authored
fix: add .from_dict() method on StepOptions, CallbackOptions, InvokeOptions and ContextOptions (#24)
1 parent b5c36f2 commit 51e75aa

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/aws_durable_execution_sdk_python/lambda_service.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ def from_dict(cls, data: MutableMapping[str, Any]) -> InvokeDetails:
211211
class StepOptions:
212212
next_attempt_delay_seconds: int = 0
213213

214+
@classmethod
215+
def from_dict(cls, data: MutableMapping[str, Any]) -> StepOptions:
216+
return cls(next_attempt_delay_seconds=data.get("NextAttemptDelaySeconds", 0))
217+
214218
def to_dict(self) -> MutableMapping[str, Any]:
215219
return {
216220
"NextAttemptDelaySeconds": self.next_attempt_delay_seconds,
@@ -234,6 +238,13 @@ class CallbackOptions:
234238
timeout_seconds: int = 0
235239
heartbeat_timeout_seconds: int = 0
236240

241+
@classmethod
242+
def from_dict(cls, data: MutableMapping[str, Any]) -> CallbackOptions:
243+
return cls(
244+
timeout_seconds=data.get("TimeoutSeconds", 0),
245+
heartbeat_timeout_seconds=data.get("HeartbeatTimeoutSeconds", 0),
246+
)
247+
237248
def to_dict(self) -> MutableMapping[str, Any]:
238249
return {
239250
"TimeoutSeconds": self.timeout_seconds,
@@ -246,6 +257,13 @@ class InvokeOptions:
246257
function_name: str
247258
timeout_seconds: int = 0
248259

260+
@classmethod
261+
def from_dict(cls, data: MutableMapping[str, Any]) -> InvokeOptions:
262+
return cls(
263+
function_name=data["FunctionName"],
264+
timeout_seconds=data.get("TimeoutSeconds", 0),
265+
)
266+
249267
def to_dict(self) -> MutableMapping[str, Any]:
250268
result: MutableMapping[str, Any] = {"FunctionName": self.function_name}
251269
result["TimeoutSeconds"] = self.timeout_seconds
@@ -256,6 +274,10 @@ def to_dict(self) -> MutableMapping[str, Any]:
256274
class ContextOptions:
257275
replay_children: bool = False
258276

277+
@classmethod
278+
def from_dict(cls, data: MutableMapping[str, Any]) -> ContextOptions:
279+
return cls(replay_children=data.get("ReplayChildren", False))
280+
259281
def to_dict(self) -> MutableMapping[str, Any]:
260282
return {"ReplayChildren": self.replay_children}
261283

0 commit comments

Comments
 (0)