@firestone-hs/reference-data 0.1.244 → 0.1.245
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/dist/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare function partitionArray<T>(array: readonly T[], partitionSize: number): readonly T[][];
|
|
2
|
-
declare function httpWithRetries(request: string, retriesLeft?: number): Promise<any>;
|
|
2
|
+
declare function httpWithRetries(request: string, retriesLeft?: number, timeBetweenRetries?: number): Promise<any>;
|
|
3
3
|
declare function http(request: string): Promise<any>;
|
|
4
4
|
declare function sleep(ms: any): Promise<unknown>;
|
|
5
5
|
export { partitionArray, http, httpWithRetries, sleep };
|
package/dist/services/utils.js
CHANGED
|
@@ -14,13 +14,15 @@ function partitionArray(array, partitionSize) {
|
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
16
16
|
exports.partitionArray = partitionArray;
|
|
17
|
-
async function httpWithRetries(request, retriesLeft = 1) {
|
|
17
|
+
async function httpWithRetries(request, retriesLeft = 1, timeBetweenRetries = 1000) {
|
|
18
|
+
console.log('fetch with retries', request, retriesLeft, timeBetweenRetries);
|
|
18
19
|
if (retriesLeft <= 0) {
|
|
19
20
|
console.error('could not load cards', request);
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
const result = await http(request);
|
|
23
24
|
if (!result) {
|
|
25
|
+
await sleep(timeBetweenRetries);
|
|
24
26
|
return httpWithRetries(request, retriesLeft - 1);
|
|
25
27
|
}
|
|
26
28
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/services/utils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAEhC,SAAS,cAAc,CAAI,KAAmB,EAAE,aAAqB;IACpE,MAAM,WAAW,GAAQ,CAAC,GAAG,KAAK,CAAC,CAAC;IACpC,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,OAAO,WAA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qBAAK,CAAC,OAAO,CAAC;aACZ,IAAI,CACJ,CAAC,QAAQ,EAAE,EAAE;YAEZ,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;YACT,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC,CACD;aACA,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YAEd,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACJ,CAAC;AAMwB,oBAAI;AAJ7B,KAAK,UAAU,KAAK,CAAC,EAAE;IACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC;AAE+C,sBAAK","sourcesContent":["import fetch from 'cross-fetch';\r\n\r\nfunction partitionArray<T>(array: readonly T[], partitionSize: number): readonly T[][] {\r\n\tconst workingCopy: T[] = [...array];\r\n\tconst result: T[][] = [];\r\n\twhile (workingCopy.length) {\r\n\t\tresult.push(workingCopy.splice(0, partitionSize));\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nasync function httpWithRetries(request: string, retriesLeft = 1, timeBetweenRetries = 1000): Promise<any> {\r\n\tconsole.log('fetch with retries', request, retriesLeft, timeBetweenRetries);\r\n\tif (retriesLeft <= 0) {\r\n\t\tconsole.error('could not load cards', request);\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst result = await http(request);\r\n\tif (!result) {\r\n\t\tawait sleep(timeBetweenRetries);\r\n\t\treturn httpWithRetries(request, retriesLeft - 1);\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nasync function http(request: string): Promise<any> {\r\n\treturn new Promise((resolve) => {\r\n\t\tfetch(request)\r\n\t\t\t.then(\r\n\t\t\t\t(response) => {\r\n\t\t\t\t\t// console.log('received response, reading text body');\r\n\t\t\t\t\treturn response.text();\r\n\t\t\t\t},\r\n\t\t\t\t(error) => {\r\n\t\t\t\t\tconsole.warn('could not load cards', error, error.message);\r\n\t\t\t\t},\r\n\t\t\t)\r\n\t\t\t.then((body) => {\r\n\t\t\t\t// console.log('sending back body', body && body.length);\r\n\t\t\t\tresolve(body);\r\n\t\t\t});\r\n\t});\r\n}\r\n\r\nasync function sleep(ms) {\r\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\r\n}\r\n\r\nexport { partitionArray, http, httpWithRetries, sleep };\r\n"]}
|