Skip to content

Commit 209ab85

Browse files
committed
Update to record is_replay
1 parent 71591fd commit 209ab85

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

aws_lambda_powertools/utilities/idempotency/base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ def __init__(
123123

124124
self.persistence_store = persistence_store
125125

126-
def handle(self, durable_mode: str | None = None) -> Any:
126+
def handle(self, is_replay: bool = False) -> Any:
127127
"""
128128
Main entry point for handling idempotent execution of a function.
129129
130130
Parameters
131131
----------
132-
durable_mode : str | None, optional
133-
Mode for handling in-progress executions. Options:
134-
- "REPLAY_MODE": Allow replay of functions that are already in progress
135-
- "EXECUTION_MODE": Standard durable execution mode
136-
- None: Standard idempotency behavior (raises IdempotencyAlreadyInProgressError)
132+
is_replay : bool, optional
133+
Whether this is a replay of a function that is already in progress.
134+
If True, allows replay of functions that are already in progress.
135+
If False, uses standard idempotency behavior (raises IdempotencyAlreadyInProgressError).
136+
Defaults to False.
137137
138138
Returns
139139
-------
@@ -146,12 +146,12 @@ def handle(self, durable_mode: str | None = None) -> Any:
146146
# In most cases we can retry successfully on this exception.
147147
for i in range(MAX_RETRIES + 1): # pragma: no cover
148148
try:
149-
return self._process_idempotency(durable_mode)
149+
return self._process_idempotency(is_replay)
150150
except IdempotencyInconsistentStateError:
151151
if i == MAX_RETRIES:
152152
raise # Bubble up when exceeded max tries
153153

154-
def _process_idempotency(self, durable_mode: str | None):
154+
def _process_idempotency(self, is_replay: bool):
155155
try:
156156
# We call save_inprogress first as an optimization for the most common case where no idempotent record
157157
# already exists. If it succeeds, there's no need to call get_record.
@@ -167,7 +167,7 @@ def _process_idempotency(self, durable_mode: str | None):
167167
# We give preference to ReturnValuesOnConditionCheckFailure because it is a faster and more cost-effective
168168
# way of retrieving the existing record after a failed conditional write operation.
169169
record = exc.old_data_record or self._get_idempotency_record()
170-
if durable_mode == "REPLAY_MODE":
170+
if is_replay:
171171
return self._get_function_response()
172172
# If a record is found, handle it for status
173173
if record:

aws_lambda_powertools/utilities/idempotency/idempotency.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ def handler(event, context):
9595
if hasattr(context, "state"):
9696
# Extract lambda_context from DurableContext for idempotency tracking
9797
config.register_lambda_context(context.lambda_context)
98-
durable_mode = "REPLAY_MODE" if len(context.state.operations) > 1 else "EXECUTION_MODE"
98+
is_replay = len(context.state.operations) > 1
9999
else:
100100
# Standard LambdaContext
101101
config.register_lambda_context(context)
102-
durable_mode = None
102+
is_replay = False
103103

104104
args = event, context
105105
idempotency_handler = IdempotencyHandler(
@@ -112,7 +112,7 @@ def handler(event, context):
112112
function_kwargs=kwargs,
113113
)
114114

115-
return idempotency_handler.handle(durable_mode=durable_mode)
115+
return idempotency_handler.handle(is_replay=is_replay)
116116

117117

118118
def idempotent_function(

0 commit comments

Comments
 (0)