@ms-cloudpack/remote-cache 0.3.0 → 0.3.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/lib/createRemoteCacheClient.js +1 -1
- package/lib/createRemoteCacheClient.js.map +1 -1
- package/lib/decorators/RetryDecorator.d.ts +1 -1
- package/lib/decorators/RetryDecorator.d.ts.map +1 -1
- package/lib/decorators/RetryDecorator.js.map +1 -1
- package/package.json +2 -1
- package/lib/retry/RetryManager.d.ts +0 -20
- package/lib/retry/RetryManager.d.ts.map +0 -1
- package/lib/retry/RetryManager.js +0 -47
- package/lib/retry/RetryManager.js.map +0 -1
|
@@ -5,7 +5,7 @@ import { ReporterDecorator } from './decorators/ReporterDecorator.js';
|
|
|
5
5
|
import { getListOfBlobs } from './getListOfBlobs.js';
|
|
6
6
|
import { RetryDecorator } from './decorators/RetryDecorator.js';
|
|
7
7
|
import { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';
|
|
8
|
-
import { RetryManager } from '
|
|
8
|
+
import { RetryManager } from '@ms-cloudpack/retry';
|
|
9
9
|
export async function createRemoteCacheClient(options) {
|
|
10
10
|
const { connectionStringOptions, context } = options;
|
|
11
11
|
const { container } = connectionStringOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAM7C;IACC,MAAM,EAAE,uBAAuB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACrD,MAAM,EAAE,SAAS,EAAE,GAAG,uBAAuB,CAAC;IAE9C,MAAM,gBAAgB,GAAG,MAAM,gCAAgC,CAAC,uBAAuB,CAAC,CAAC;IAEzF,MAAM,kBAAkB,GAAG;QACzB,SAAS;QACT,gBAAgB;KACjB,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAClC,IAAI,cAAc,CAAC;QACjB,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,6BAA6B,CAAC,CAAC;QAC/D,WAAW,EAAE,IAAI,iBAAiB,CAAC;YACjC,WAAW,EAAE,IAAI,sBAAsB,CAAC,kBAAkB,CAAC;YAC3D,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,kBAAkB,CAAC;SAClD,CAAC;KACH,CAAC,EACF,OAAO,CACR,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';\nimport { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';\nimport { InMemoryDecorator } from './decorators/InMemoryDecorator.js';\nimport { ReporterDecorator } from './decorators/ReporterDecorator.js';\nimport { getListOfBlobs } from './getListOfBlobs.js';\nimport type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';\nimport type { RemoteCacheClient } from './types/RemoteCacheClient.js';\nimport { RetryDecorator } from './decorators/RetryDecorator.js';\nimport { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';\nimport { RetryManager } from '@ms-cloudpack/retry';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\n\nexport async function createRemoteCacheClient(options: {\n connectionStringOptions: ConnectionStringOptions;\n context: {\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n };\n}): Promise<RemoteCacheClient> {\n const { connectionStringOptions, context } = options;\n const { container } = connectionStringOptions;\n\n const connectionString = await getAuthenticatedConnectionString(connectionStringOptions);\n\n const cacheClientOptions = {\n container,\n connectionString,\n };\n\n const client = new ReporterDecorator(\n new RetryDecorator({\n retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),\n cacheClient: new InMemoryDecorator({\n cacheClient: new AzureRemoteCacheClient(cacheClientOptions),\n getList: () => getListOfBlobs(cacheClientOptions),\n }),\n }),\n context,\n );\n\n return client;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RemoteCacheClient, RemoteCacheClientDownloadOperationOptions, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult } from '../types/RemoteCacheClient.js';
|
|
2
|
-
import type { RetryManager } from '
|
|
2
|
+
import type { RetryManager } from '@ms-cloudpack/retry';
|
|
3
3
|
/**
|
|
4
4
|
* A decorator that retries the upload/download operation if it fails.
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,qBAAa,cAAe,YAAW,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,OAAO,EAAE;QAAE,WAAW,EAAE,iBAAiB,CAAC;QAAC,YAAY,EAAE,YAAY,CAAA;KAAE;IAKnF,OAAO,CAAC,iBAAiB;IAYnB,YAAY,CAAC,OAAO,EAAE,yCAAyC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAO3G,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAM5G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;SACH;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '
|
|
1
|
+
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;SACH;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '@ms-cloudpack/retry';\n\n/**\n * A decorator that retries the upload/download operation if it fails.\n */\nexport class RetryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly retryManager: RetryManager;\n\n constructor(options: { cacheClient: RemoteCacheClient; retryManager: RetryManager }) {\n this.cacheClient = options.cacheClient;\n this.retryManager = options.retryManager;\n }\n\n private printRetryContext(\n operationName: string,\n options: RemoteCacheClientOperationOptions,\n retryContext?: { retryAttempt: number; maxRetries: number },\n ) {\n if (retryContext) {\n console.warn(\n `Retrying ${operationName} ${options.friendlyName} ... [${retryContext.retryAttempt}/${retryContext.maxRetries}]`,\n );\n }\n }\n\n async uploadFolder(options: RemoteCacheClientDownloadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('upload', options, retryContext);\n return this.cacheClient.uploadFolder(options);\n });\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('download', options, retryContext);\n return this.cacheClient.downloadFolder(options);\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/remote-cache",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ms-cloudpack/task-reporter": "^0.10.2",
|
|
35
35
|
"@ms-cloudpack/telemetry": "^0.4.4",
|
|
36
|
+
"@ms-cloudpack/retry": "^0.1.1",
|
|
36
37
|
"@azure/identity": "^3.4.0",
|
|
37
38
|
"@azure/storage-blob": "^12.17.0",
|
|
38
39
|
"@napi-rs/keyring": "^1.1.3",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { RetryPolicy } from '../types/RetryPolicy.js';
|
|
2
|
-
/**
|
|
3
|
-
* A manager that handles the retry logic.
|
|
4
|
-
*/
|
|
5
|
-
export declare class RetryManager {
|
|
6
|
-
private readonly policies;
|
|
7
|
-
constructor(policies: RetryPolicy[]);
|
|
8
|
-
private findPolicy;
|
|
9
|
-
private sleep;
|
|
10
|
-
/**
|
|
11
|
-
* If the operation call fails and there is an applicable retry policy, it will retry the operation.
|
|
12
|
-
* @param operation The operation to call. The retry context is passed to the operation if it is in retry.
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
retry<T>(operation: (retryContext?: {
|
|
16
|
-
retryAttempt: number;
|
|
17
|
-
maxRetries: number;
|
|
18
|
-
}) => Promise<T>): Promise<T>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=RetryManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RetryManager.d.ts","sourceRoot":"","sources":["../../src/retry/RetryManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,WAAW,EAAE;IAEpD,OAAO,CAAC,UAAU,CAOhB;IAEF,OAAO,CAAC,KAAK;IAIb;;;;OAIG;IACU,KAAK,CAAC,CAAC,EAClB,SAAS,EAAE,CAAC,YAAY,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GACrF,OAAO,CAAC,CAAC,CAAC;CAyBd"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A manager that handles the retry logic.
|
|
3
|
-
*/
|
|
4
|
-
export class RetryManager {
|
|
5
|
-
constructor(policies) {
|
|
6
|
-
this.policies = policies;
|
|
7
|
-
this.findPolicy = (error) => {
|
|
8
|
-
for (const policy of this.policies) {
|
|
9
|
-
if (policy.handle(error)) {
|
|
10
|
-
return policy;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
sleep(ms) {
|
|
17
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* If the operation call fails and there is an applicable retry policy, it will retry the operation.
|
|
21
|
-
* @param operation The operation to call. The retry context is passed to the operation if it is in retry.
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
async retry(operation) {
|
|
25
|
-
let retryAttempt = 0;
|
|
26
|
-
let previousPolicy = undefined;
|
|
27
|
-
do {
|
|
28
|
-
try {
|
|
29
|
-
const retryContext = previousPolicy ? { retryAttempt, maxRetries: previousPolicy.maxRetries } : undefined;
|
|
30
|
-
return await operation(retryContext);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
const policy = this.findPolicy(e);
|
|
34
|
-
if (previousPolicy !== policy) {
|
|
35
|
-
retryAttempt = 0;
|
|
36
|
-
previousPolicy = policy;
|
|
37
|
-
}
|
|
38
|
-
if (!policy || retryAttempt++ >= policy.maxRetries) {
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
await this.sleep(policy.wait(retryAttempt));
|
|
42
|
-
}
|
|
43
|
-
// eslint-disable-next-line no-constant-condition
|
|
44
|
-
} while (true);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=RetryManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RetryManager.js","sourceRoot":"","sources":["../../src/retry/RetryManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;QAE5C,eAAU,GAAG,CAAC,KAAc,EAA2B,EAAE;YAC/D,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;gBAClC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBACxB,OAAO,MAAM,CAAC;iBACf;aACF;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;IATqD,CAAC;IAWhD,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAK,CAChB,SAAsF;QAEtF,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,cAAc,GAA4B,SAAS,CAAC;QAExD,GAAG;YACD,IAAI;gBACF,MAAM,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;gBAE1G,OAAO,MAAM,SAAS,CAAC,YAAY,CAAC,CAAC;aACtC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,cAAc,KAAK,MAAM,EAAE;oBAC7B,YAAY,GAAG,CAAC,CAAC;oBACjB,cAAc,GAAG,MAAM,CAAC;iBACzB;gBAED,IAAI,CAAC,MAAM,IAAI,YAAY,EAAE,IAAI,MAAM,CAAC,UAAU,EAAE;oBAClD,MAAM,CAAC,CAAC;iBACT;gBAED,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;aAC7C;YACD,iDAAiD;SAClD,QAAQ,IAAI,EAAE;IACjB,CAAC;CACF","sourcesContent":["import type { RetryPolicy } from '../types/RetryPolicy.js';\n\n/**\n * A manager that handles the retry logic.\n */\nexport class RetryManager {\n constructor(private readonly policies: RetryPolicy[]) {}\n\n private findPolicy = (error: unknown): RetryPolicy | undefined => {\n for (const policy of this.policies) {\n if (policy.handle(error)) {\n return policy;\n }\n }\n return undefined;\n };\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * If the operation call fails and there is an applicable retry policy, it will retry the operation.\n * @param operation The operation to call. The retry context is passed to the operation if it is in retry.\n * @returns\n */\n public async retry<T>(\n operation: (retryContext?: { retryAttempt: number; maxRetries: number }) => Promise<T>,\n ): Promise<T> {\n let retryAttempt = 0;\n let previousPolicy: RetryPolicy | undefined = undefined;\n\n do {\n try {\n const retryContext = previousPolicy ? { retryAttempt, maxRetries: previousPolicy.maxRetries } : undefined;\n\n return await operation(retryContext);\n } catch (e) {\n const policy = this.findPolicy(e);\n if (previousPolicy !== policy) {\n retryAttempt = 0;\n previousPolicy = policy;\n }\n\n if (!policy || retryAttempt++ >= policy.maxRetries) {\n throw e;\n }\n\n await this.sleep(policy.wait(retryAttempt));\n }\n // eslint-disable-next-line no-constant-condition\n } while (true);\n }\n}\n"]}
|