@tc-libs/retry-policy 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +52 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,57 @@
1
- # retry-policy
1
+ # @tc-libs/retry-policy
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Package minimale per retry di transazioni MongoDB con backoff esponenziale.
4
4
 
5
- ## Building
5
+ Espone un solo servizio globale: `RetryPolicyMongoService`.
6
6
 
7
- Run `nx build retry-policy` to build the library.
7
+ ## Quando usarlo
8
8
 
9
- ## Running unit tests
9
+ Usalo quando esegui una transazione Mongo che puo fallire con errori transienti come:
10
10
 
11
- Run `nx test retry-policy` to execute the unit tests via [Jest](https://jestjs.io).
11
+ - `WriteConflict`
12
+ - `TransientTransactionError`
13
+ - `UnknownTransactionCommitResult`
14
+
15
+ ## Uso
16
+
17
+ ```ts
18
+ const session = await this.repo.startTransaction();
19
+
20
+ await this.retryPolicyMongoService.runInTransactionWithRetry(
21
+ session,
22
+ async (session) => {
23
+ await this.userRepository.updateOne({ _id: userId }, update, { session });
24
+ await this.auditRepository.create(payload, { session });
25
+ },
26
+ {
27
+ maxRetries: 5,
28
+ baseDelayMs: 50,
29
+ maxDelayMs: 2000,
30
+ jitter: true,
31
+ },
32
+ );
33
+ ```
34
+
35
+ ## Comportamento
36
+
37
+ - avvia la transazione se la sessione non e gia in transaction
38
+ - esegue `commitTransaction`
39
+ - se trova un errore retryable esegue `abortTransaction`, aspetta il delay e riprova
40
+ - rilancia l'errore quando il retry non e piu consentito
41
+
42
+ ## Modulo
43
+
44
+ Il modulo e globale:
45
+
46
+ ```ts
47
+ import { RetryPolicyModule } from '@tc-libs/retry-policy';
48
+ ```
49
+
50
+ Non richiede configurazione.
51
+
52
+ ## Sviluppo
53
+
54
+ ```bash
55
+ nx build retry-policy
56
+ nx test retry-policy
57
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tc-libs/retry-policy",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
5
  "@nestjs/common": "^11.0.12",
6
6
  "mongodb": "6.15.0",