Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/aws_durable_execution_sdk_python_testing/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def get_execution_details(self, execution_arn: str) -> GetDurableExecutionRespon
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_date=execution_op.start_timestamp.isoformat()
start_timestamp=execution_op.start_timestamp.isoformat()
if execution_op.start_timestamp
else datetime.now(UTC).isoformat(),
input_payload=execution_op.execution_details.input_payload
if execution_op.execution_details
else None,
result=result,
error=error,
stop_date=execution_op.end_timestamp.isoformat()
end_timestamp=execution_op.end_timestamp.isoformat()
if execution_op.end_timestamp
else None,
version="1.0",
Expand Down Expand Up @@ -223,17 +223,17 @@ def list_executions(
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=execution_status,
start_date=execution_op.start_timestamp.isoformat()
start_timestamp=execution_op.start_timestamp.isoformat()
if execution_op.start_timestamp
else datetime.now(UTC).isoformat(),
stop_date=execution_op.end_timestamp.isoformat()
end_timestamp=execution_op.end_timestamp.isoformat()
if execution_op.end_timestamp
else None,
)
filtered_executions.append(execution_summary)

# Sort by start date
filtered_executions.sort(key=lambda e: e.start_date, reverse=reverse_order)
filtered_executions.sort(key=lambda e: e.start_timestamp, reverse=reverse_order)

# Apply pagination
if max_items is None:
Expand Down
30 changes: 16 additions & 14 deletions src/aws_durable_execution_sdk_python_testing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ class GetDurableExecutionResponse:
durable_execution_name: str
function_arn: str
status: str
start_date: str
start_timestamp: str
input_payload: str | None = None
result: str | None = None
error: ErrorObject | None = None
stop_date: str | None = None
end_timestamp: str | None = None
version: str | None = None

@classmethod
Expand All @@ -149,11 +149,11 @@ def from_dict(cls, data: dict) -> GetDurableExecutionResponse:
durable_execution_name=data["DurableExecutionName"],
function_arn=data["FunctionArn"],
status=data["Status"],
start_date=data["StartDate"],
start_timestamp=data["StartTimestamp"],
input_payload=data.get("InputPayload"),
result=data.get("Result"),
error=error,
stop_date=data.get("StopDate"),
end_timestamp=data.get("EndTimestamp"),
version=data.get("Version"),
)

Expand All @@ -163,16 +163,18 @@ def to_dict(self) -> dict[str, Any]:
"DurableExecutionName": self.durable_execution_name,
"FunctionArn": self.function_arn,
"Status": self.status,
"StartDate": self.start_date,
"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.stop_date is not None:
result["StopDate"] = self.stop_date
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
Expand All @@ -186,8 +188,8 @@ class Execution:
durable_execution_name: str
function_arn: str
status: str
start_date: str
stop_date: str | None = None
start_timestamp: str
end_timestamp: str | None = None

@classmethod
def from_dict(cls, data: dict) -> Execution:
Expand All @@ -198,21 +200,21 @@ def from_dict(cls, data: dict) -> Execution:
"FunctionArn", ""
), # Make optional for backward compatibility
status=data["Status"],
start_date=data["StartDate"],
stop_date=data.get("StopDate"),
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,
"StartDate": self.start_date,
"StartTimestamp": self.start_timestamp,
}
if self.function_arn: # Only include if not empty
result["FunctionArn"] = self.function_arn
if self.stop_date is not None:
result["StopDate"] = self.stop_date
if self.end_timestamp is not None:
result["EndTimestamp"] = self.end_timestamp
return result


Expand Down
46 changes: 23 additions & 23 deletions tests/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ def test_get_durable_execution_response_serialization():
"DurableExecutionName": "test-execution",
"FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"InputPayload": "test-input",
"Result": "test-result",
"Error": {"ErrorMessage": "test error"},
"StopDate": "2023-01-01T00:01:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
"Version": "1.0",
}

Expand All @@ -199,11 +199,11 @@ def test_get_durable_execution_response_serialization():
== "arn:aws:lambda:us-east-1:123456789012:function:my-function"
)
assert response_obj.status == "SUCCEEDED"
assert response_obj.start_date == "2023-01-01T00:00:00Z"
assert response_obj.start_timestamp == "2023-01-01T00:00:00Z"
assert response_obj.input_payload == "test-input"
assert response_obj.result == "test-result"
assert response_obj.error.message == "test error"
assert response_obj.stop_date == "2023-01-01T00:01:00Z"
assert response_obj.end_timestamp == "2023-01-01T00:01:00Z"
assert response_obj.version == "1.0"

result_data = response_obj.to_dict()
Expand All @@ -221,14 +221,14 @@ def test_get_durable_execution_response_minimal():
"DurableExecutionName": "test-execution",
"FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function",
"Status": "RUNNING",
"StartDate": "2023-01-01T00:00:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
}

response_obj = GetDurableExecutionResponse.from_dict(data)
assert response_obj.input_payload is None
assert response_obj.result is None
assert response_obj.error is None
assert response_obj.stop_date is None
assert response_obj.end_timestamp is None
assert response_obj.version is None

result_data = response_obj.to_dict()
Expand Down Expand Up @@ -295,8 +295,8 @@ def test_durable_execution_summary_serialization():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test",
"DurableExecutionName": "test-execution",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
}

summary_obj = Execution.from_dict(data)
Expand All @@ -306,8 +306,8 @@ def test_durable_execution_summary_serialization():
)
assert summary_obj.durable_execution_name == "test-execution"
assert summary_obj.status == "SUCCEEDED"
assert summary_obj.start_date == "2023-01-01T00:00:00Z"
assert summary_obj.stop_date == "2023-01-01T00:01:00Z"
assert summary_obj.start_timestamp == "2023-01-01T00:00:00Z"
assert summary_obj.end_timestamp == "2023-01-01T00:01:00Z"

result_data = summary_obj.to_dict()
assert result_data == data
Expand All @@ -323,11 +323,11 @@ def test_durable_execution_summary_no_stop_date():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test",
"DurableExecutionName": "test-execution",
"Status": "RUNNING",
"StartDate": "2023-01-01T00:00:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
}

summary_obj = Execution.from_dict(data)
assert summary_obj.stop_date is None
assert summary_obj.end_timestamp is None

result_data = summary_obj.to_dict()
assert result_data == data
Expand All @@ -341,14 +341,14 @@ def test_list_durable_executions_response_serialization():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test1",
"DurableExecutionName": "test-execution-1",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
},
{
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test2",
"DurableExecutionName": "test-execution-2",
"Status": "RUNNING",
"StartDate": "2023-01-01T00:02:00Z",
"StartTimestamp": "2023-01-01T00:02:00Z",
},
],
"NextMarker": "next-marker-123",
Expand Down Expand Up @@ -738,8 +738,8 @@ def test_list_durable_executions_by_function_response_serialization():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test1",
"DurableExecutionName": "test-execution-1",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
}
],
"NextMarker": "next-marker-123",
Expand Down Expand Up @@ -1183,8 +1183,8 @@ def test_execution_backward_compatibility_empty_function_arn():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test",
"DurableExecutionName": "test-execution",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
}

execution_obj = Execution.from_dict(data)
Expand All @@ -1198,8 +1198,8 @@ def test_execution_backward_compatibility_empty_function_arn():
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function:execution:test",
"DurableExecutionName": "test-execution",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
}
assert result_data == expected_data

Expand All @@ -1211,8 +1211,8 @@ def test_execution_with_function_arn():
"DurableExecutionName": "test-execution",
"FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function",
"Status": "SUCCEEDED",
"StartDate": "2023-01-01T00:00:00Z",
"StopDate": "2023-01-01T00:01:00Z",
"StartTimestamp": "2023-01-01T00:00:00Z",
"EndTimestamp": "2023-01-01T00:01:00Z",
}

execution_obj = Execution.from_dict(data)
Expand Down
Loading