@naturalcycles/js-lib 14.247.0 → 14.247.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/dist/promise/pRetry.js
CHANGED
|
@@ -15,7 +15,7 @@ function pRetryFn(fn, opt = {}) {
|
|
|
15
15
|
async function pRetry(fn, opt = {}) {
|
|
16
16
|
const { maxAttempts = 4, delay: initialDelay = 1000, delayMultiplier = 2, predicate, logger = console, name, timeout, } = opt;
|
|
17
17
|
const fakeError = timeout ? new Error('TimeoutError') : undefined;
|
|
18
|
-
let { logFirstAttempt = false, logRetries = true, logFailures =
|
|
18
|
+
let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt;
|
|
19
19
|
if (opt.logAll) {
|
|
20
20
|
logSuccess = logFirstAttempt = logRetries = logFailures = true;
|
|
21
21
|
}
|
|
@@ -51,7 +51,7 @@ async function pRetry(fn, opt = {}) {
|
|
|
51
51
|
}
|
|
52
52
|
catch (err) {
|
|
53
53
|
if (logFailures) {
|
|
54
|
-
logger.
|
|
54
|
+
logger.error(`${fname} attempt #${attempt} error in ${(0, __1._since)(started)}:`, err);
|
|
55
55
|
}
|
|
56
56
|
if (attempt >= maxAttempts || (predicate && !predicate(err, attempt, maxAttempts))) {
|
|
57
57
|
// Give up
|
|
@@ -11,7 +11,7 @@ export function pRetryFn(fn, opt = {}) {
|
|
|
11
11
|
export async function pRetry(fn, opt = {}) {
|
|
12
12
|
const { maxAttempts = 4, delay: initialDelay = 1000, delayMultiplier = 2, predicate, logger = console, name, timeout, } = opt;
|
|
13
13
|
const fakeError = timeout ? new Error('TimeoutError') : undefined;
|
|
14
|
-
let { logFirstAttempt = false, logRetries = true, logFailures =
|
|
14
|
+
let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt;
|
|
15
15
|
if (opt.logAll) {
|
|
16
16
|
logSuccess = logFirstAttempt = logRetries = logFailures = true;
|
|
17
17
|
}
|
|
@@ -47,7 +47,7 @@ export async function pRetry(fn, opt = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
catch (err) {
|
|
49
49
|
if (logFailures) {
|
|
50
|
-
logger.
|
|
50
|
+
logger.error(`${fname} attempt #${attempt} error in ${_since(started)}:`, err);
|
|
51
51
|
}
|
|
52
52
|
if (attempt >= maxAttempts || (predicate && !predicate(err, attempt, maxAttempts))) {
|
|
53
53
|
// Give up
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.247.
|
|
3
|
+
"version": "14.247.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
|
-
"build
|
|
6
|
+
"build": "dev-lib build-esm-cjs",
|
|
7
|
+
"test": "dev-lib test",
|
|
8
|
+
"lint": "dev-lib lint",
|
|
9
|
+
"bt": "dev-lib bt",
|
|
10
|
+
"lbt": "dev-lib lbt",
|
|
7
11
|
"test-tz1": "TZ=Europe/Stockholm yarn test local",
|
|
8
12
|
"test-tz2": "TZ=JST-9 yarn test local",
|
|
9
13
|
"test-ny": "TZ=GMT-0500 yarn test localTime",
|
|
@@ -17,11 +21,11 @@
|
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@naturalcycles/bench-lib": "^3.0.0",
|
|
20
|
-
"@naturalcycles/dev-lib": "^
|
|
24
|
+
"@naturalcycles/dev-lib": "^15.0.3",
|
|
21
25
|
"@naturalcycles/nodejs-lib": "^13.0.1",
|
|
22
26
|
"@naturalcycles/time-lib": "^3.5.1",
|
|
23
27
|
"@types/crypto-js": "^4.1.1",
|
|
24
|
-
"@types/node": "^
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
25
29
|
"@types/semver": "^7.5.8",
|
|
26
30
|
"crypto-js": "^4.1.1",
|
|
27
31
|
"jest": "^29.0.0",
|
package/src/promise/pRetry.ts
CHANGED
|
@@ -114,7 +114,7 @@ export async function pRetry<T>(
|
|
|
114
114
|
} = opt
|
|
115
115
|
|
|
116
116
|
const fakeError = timeout ? new Error('TimeoutError') : undefined
|
|
117
|
-
let { logFirstAttempt = false, logRetries = true, logFailures =
|
|
117
|
+
let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt
|
|
118
118
|
|
|
119
119
|
if (opt.logAll) {
|
|
120
120
|
logSuccess = logFirstAttempt = logRetries = logFailures = true
|
|
@@ -157,7 +157,7 @@ export async function pRetry<T>(
|
|
|
157
157
|
return result
|
|
158
158
|
} catch (err) {
|
|
159
159
|
if (logFailures) {
|
|
160
|
-
logger.
|
|
160
|
+
logger.error(`${fname} attempt #${attempt} error in ${_since(started)}:`, err)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
if (attempt >= maxAttempts || (predicate && !predicate(err as Error, attempt, maxAttempts))) {
|