@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.
- package/README.md +52 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,57 @@
|
|
|
1
|
-
# retry-policy
|
|
1
|
+
# @tc-libs/retry-policy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Package minimale per retry di transazioni MongoDB con backoff esponenziale.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Espone un solo servizio globale: `RetryPolicyMongoService`.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Quando usarlo
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Usalo quando esegui una transazione Mongo che puo fallire con errori transienti come:
|
|
10
10
|
|
|
11
|
-
|
|
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
|
+
```
|