Skip to content

Commit 82985ca

Browse files
authored
fix(plugin): set OperationStartInfo start_time from operation (#559)
1 parent b448f3e commit 82985ca

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import datetime
55
import functools
66
import logging
7+
from collections.abc import Mapping, Sequence
78
from concurrent.futures import ThreadPoolExecutor
89
from dataclasses import dataclass, field
910
from enum import Enum
10-
from collections.abc import Mapping, Sequence
1111
from typing import Any, Callable, MutableMapping, cast
1212

1313
from aws_durable_execution_sdk_python.identifier import OperationIdentifier
@@ -381,7 +381,9 @@ def on_user_function_end(self, start_info: UserFunctionStartInfo, error) -> None
381381
UserFunctionEndInfo.from_start_info(start_info, error), sync=True
382382
)
383383

384-
def on_operation_action(self, update: OperationUpdate):
384+
def on_operation_action(
385+
self, update: OperationUpdate, operation: Operation | None = None
386+
):
385387
"""Execute any registered plugins for a given operation when an update is checkpointed
386388
387389
Args:
@@ -398,7 +400,7 @@ def on_operation_action(self, update: OperationUpdate):
398400
sub_type=update.sub_type,
399401
name=update.name,
400402
parent_id=update.parent_id,
401-
start_time=datetime.datetime.now(datetime.UTC),
403+
start_time=operation.start_timestamp if operation else None,
402404
is_replayed=False,
403405
status=OperationStatus.STARTED,
404406
),

packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/state.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,9 @@ def checkpoint_batches_forever(self) -> None:
751751
output.new_execution_state.next_marker,
752752
)
753753
for update in updates:
754-
self._plugin_executor.on_operation_action(update)
754+
self._plugin_executor.on_operation_action(
755+
update, self.operations.get(update.operation_id)
756+
)
755757

756758
self._plugin_executor.on_operation_update(
757759
updated_operations,

packages/aws-durable-execution-sdk-python/tests/plugin_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,36 @@ def on_operation_start(self, info: OperationStartInfo) -> None:
554554
self.assertIn("operation_start:op-1", self.plugin.calls)
555555
self.assertEqual(captured[0].status, OperationStatus.STARTED)
556556

557+
def test_start_action_uses_server_start_timestamp(self):
558+
captured: list[OperationStartInfo] = []
559+
560+
class _CapturingPlugin(_TrackingPlugin):
561+
def on_operation_start(self, info: OperationStartInfo) -> None:
562+
super().on_operation_start(info)
563+
captured.append(info)
564+
565+
self.plugin = _CapturingPlugin()
566+
self.executor = PluginExecutor(plugins=[self.plugin])
567+
update = MagicMock()
568+
update.action = OperationAction.START
569+
update.operation_id = "op-1"
570+
update.operation_type = OperationType.STEP
571+
update.sub_type = OperationSubType.STEP
572+
update.name = "my-step"
573+
update.parent_id = "parent-1"
574+
575+
operation = Operation(
576+
operation_id="op-1",
577+
operation_type=OperationType.STEP,
578+
status=OperationStatus.STARTED,
579+
start_timestamp=START_TS,
580+
)
581+
582+
with self.executor.run():
583+
self.executor.on_operation_action(update, operation)
584+
585+
self.assertEqual(captured[0].start_time, START_TS)
586+
557587
def test_non_start_action_does_not_fire(self):
558588
update = MagicMock()
559589
update.action = OperationAction.SUCCEED

0 commit comments

Comments
 (0)