You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+45-7
Original file line number
Diff line number
Diff line change
@@ -454,6 +454,40 @@ sequenceDiagram
454
454
<i>Idempotent successful request cached</i>
455
455
</center>
456
456
457
+
#### Successful request with response_hook configured
458
+
459
+
<center>
460
+
```mermaid
461
+
sequenceDiagram
462
+
participant Client
463
+
participant Lambda
464
+
participant Response hook
465
+
participant Persistence Layer
466
+
alt initial request
467
+
Client->>Lambda: Invoke (event)
468
+
Lambda->>Persistence Layer: Get or set idempotency_key=hash(payload)
469
+
activate Persistence Layer
470
+
Note over Lambda,Persistence Layer: Set record status to INPROGRESS. <br> Prevents concurrent invocations <br> with the same payload
471
+
Lambda-->>Lambda: Call your function
472
+
Lambda->>Persistence Layer: Update record with result
473
+
deactivate Persistence Layer
474
+
Persistence Layer-->>Persistence Layer: Update record
475
+
Note over Lambda,Persistence Layer: Set record status to COMPLETE. <br> New invocations with the same payload <br> now return the same result
476
+
Lambda-->>Client: Response sent to client
477
+
else retried request
478
+
Client->>Lambda: Invoke (event)
479
+
Lambda->>Persistence Layer: Get or set idempotency_key=hash(payload)
480
+
activate Persistence Layer
481
+
Persistence Layer-->>Response hook: Already exists in persistence layer.
482
+
deactivate Persistence Layer
483
+
Note over Response hook,Persistence Layer: Record status is COMPLETE and not expired
484
+
Response hook->>Lambda: Response hook invoked
485
+
Lambda-->>Client: Same response sent to client
486
+
end
487
+
```
488
+
<i>Idempotent successful request with response hook</i>
489
+
</center>
490
+
457
491
#### Expired idempotency records
458
492
459
493
<center>
@@ -708,7 +742,7 @@ Idempotent decorator can be further configured with **`IdempotencyConfig`** as s
708
742
|**use_local_cache**|`False`| Whether to locally cache idempotency results |
709
743
|**local_cache_max_items**| 256 | Max number of items to store in local cache |
710
744
|**hash_function**|`md5`| Function to use for calculating hashes, as provided by [hashlib](https://docs.python.org/3/library/hashlib.html){target="_blank" rel="nofollow"} in the standard library. |
711
-
|**response_hook**|`None`| Function to use for processing the stored Idempotent response. This function hook is called when an existing idempotent response is found. See [Manipulating The Idempotent Response](idempotency.md#manipulating-the-idempotent-response)|
745
+
|**response_hook**|`None`| Function to use for processing the stored Idempotent response. This function hook is called when an existing idempotent response is found. See [Manipulating The Idempotent Response](idempotency.md#manipulating-the-idempotent-response)|
712
746
713
747
### Handling concurrent executions with the same payload
714
748
@@ -912,15 +946,19 @@ You can create your own persistent store from scratch by inheriting the `BasePer
912
946
913
947
### Manipulating the Idempotent Response
914
948
915
-
The IdempotentConfig allows you to specify a _**response_hook**_ which is a function that will be called when an already returned response is loaded from the PersistenceStore. The Hook function will be called with the current de-serialized response object and the Idempotent DataRecord.
916
-
917
-
You can provide the _**response_hook**_ using _**IdempotentConfig**_.
949
+
You can set up a `response_hook` in the `IdempotentConfig` class to access the returned data when an operation is idempotent. The hook function will be called with the current deserialized response object and the Idempotency record.
0 commit comments