@f5devcentral/f5-cloud-libs
Advanced tools
Comparing version 4.27.1 to 4.28.0
@@ -1000,2 +1000,9 @@ /** | ||
const retry = retryOptions || util.DEFAULT_RETRY_IGNORE_ERRORS; | ||
retry.shortRetryOnError = { | ||
codes: [401], | ||
retryOptions: { | ||
maxRetries: 5, | ||
retryIntervalMs: 5000 | ||
} | ||
}; | ||
@@ -1002,0 +1009,0 @@ const func = function () { |
@@ -174,2 +174,11 @@ /** | ||
* code matches any value in array. | ||
* @param {Object} [retryOptions.shortRetryOnError] - Retry for a limited number of | ||
* times on a specified error. | ||
* @param {Integer} [retryOptions.shortRetryOnError.codes] - The codes that we should shorten | ||
* the retries on. | ||
* @param {Object} [retryOptions.shortRetryOnError.retryOptions] - Options for retrying the | ||
* request. Currently | ||
* maxRetries and | ||
* retryIntervalMs are | ||
* supported. | ||
* @param {Function} funcToTry - Function to try. Function should | ||
@@ -186,2 +195,3 @@ * return a Promise which is later | ||
let deferred; | ||
let resumeRetries; | ||
@@ -225,2 +235,3 @@ const shouldReject = function (err) { | ||
let numRemaining = maxRetries; | ||
let retryInterval = interval; | ||
let promise; | ||
@@ -238,4 +249,17 @@ | ||
} else if (numRemaining > 0) { | ||
numRemaining -= 1; | ||
setTimeout(tryIt, interval, numRemaining, interval, theFunc, deferred); | ||
if (retryOptions.shortRetryOnError && err | ||
&& retryOptions.shortRetryOnError.codes.indexOf(err.code) > -1 && !resumeRetries) { | ||
resumeRetries = numRemaining; | ||
numRemaining = retryOptions.shortRetryOnError.retryOptions.maxRetries; | ||
retryInterval = retryOptions | ||
.shortRetryOnError.retryOptions.retryIntervalMs || interval; | ||
} else if (retryOptions.shortRetryOnError && err | ||
&& retryOptions.shortRetryOnError.codes.indexOf(err.code) < 0 && resumeRetries) { | ||
numRemaining = resumeRetries; | ||
resumeRetries = undefined; | ||
retryInterval = retryOptions.retryIntervalMs; | ||
} else { | ||
numRemaining -= 1; | ||
} | ||
setTimeout(tryIt, retryInterval, numRemaining, retryInterval, theFunc, deferred); | ||
} else { | ||
@@ -242,0 +266,0 @@ logger.verbose('Max tries reached.'); |
{ | ||
"name": "@f5devcentral/f5-cloud-libs", | ||
"version": "4.27.1", | ||
"version": "4.28.0", | ||
"description": "Common library code and scripts for deploying a BIG-IP in a cloud environment", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# Release notes | ||
## Release 4.28.0 | ||
* Updated tryUntil to allow for a new shortRetryOnError to allow us to try less on specified error codes | ||
## Release 4.27.1 | ||
@@ -4,0 +7,0 @@ * Updated autoscale.js and createRandomUser function to reset password on temporary account creation |
@@ -36,3 +36,3 @@ /** | ||
return options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -39,0 +39,0 @@ '--host <ip_address>', |
@@ -42,3 +42,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -45,0 +45,0 @@ '--data-file <data_file>', |
@@ -61,3 +61,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -64,0 +64,0 @@ '--background', |
@@ -35,3 +35,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -38,0 +38,0 @@ '--length <password_length>', |
@@ -55,3 +55,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -58,0 +58,0 @@ '--cloud <cloud_provider>', |
@@ -73,3 +73,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -76,0 +76,0 @@ '--host <ip_address>', |
@@ -52,3 +52,3 @@ /** | ||
options | ||
.version('4.27.1') | ||
.version('4.28.0') | ||
.option( | ||
@@ -55,0 +55,0 @@ '--background', |
@@ -1626,2 +1626,103 @@ /** | ||
}); | ||
describe('shortRetryOnError', () => { | ||
const retryOptions = { | ||
maxRetries: 20, | ||
retryIntervalMs: 1, | ||
continueOnError: true, | ||
shortRetryOnError: { | ||
codes: [401], | ||
retryOptions: { | ||
maxRetries: 2, | ||
retryIntervalMs: 1 | ||
} | ||
} | ||
}; | ||
it('should use shortRetryOnError when specified code happens', () => { | ||
const func = function () { | ||
funcCount += 1; | ||
return q.reject({ code: 401, message: '401 Unauthorized' }); | ||
}; | ||
return util.tryUntil(this, retryOptions, func) | ||
.then(() => { | ||
return assert.ok(false, 'func should not have made it to resolution'); | ||
}) | ||
.catch((err) => { | ||
assert.deepStrictEqual( | ||
err, | ||
{ | ||
code: 401, | ||
message: 'tryUntil: max tries reached: 401 Unauthorized', | ||
name: '' | ||
} | ||
); | ||
assert.strictEqual(funcCount, 4); | ||
}); | ||
}); | ||
it('should resume retries when shortRetryOnError.codes is no longer encountered', () => { | ||
const func = function () { | ||
funcCount += 1; | ||
switch (funcCount) { | ||
case 1: | ||
return q.reject({ code: 401, message: '401 Unauthorized' }); | ||
case 2: | ||
return q.reject({ code: 401, message: '401 Unauthorized' }); | ||
default: | ||
return q.reject({ code: 500, message: 'Not a 401' }); | ||
} | ||
}; | ||
return util.tryUntil(this, retryOptions, func) | ||
.then(() => { | ||
return assert.ok(false, 'func should not have made it to resolution'); | ||
}) | ||
.catch((err) => { | ||
assert.deepStrictEqual( | ||
err, | ||
{ | ||
code: 500, | ||
message: 'tryUntil: max tries reached: Not a 401', | ||
name: '' | ||
} | ||
); | ||
assert.strictEqual(funcCount, 24); | ||
}); | ||
}); | ||
it('should handle multiple codes in shortRetryOnError', () => { | ||
retryOptions.shortRetryOnError.codes = [401, 404]; | ||
const func = function () { | ||
funcCount += 1; | ||
switch (funcCount) { | ||
case 1: | ||
return q.reject({ code: 401, message: '401 Unauthorized' }); | ||
case 2: | ||
return q.reject({ code: 401, message: '401 Unauthorized' }); | ||
case 3: | ||
return q.reject({ code: 400, message: 'Not in shortRetryOnError.codes' }); | ||
default: | ||
return q.reject({ code: 404, message: 'Not a 401' }); | ||
} | ||
}; | ||
return util.tryUntil(this, retryOptions, func) | ||
.then(() => { | ||
return assert.ok(false, 'func should not have made it to resolution'); | ||
}) | ||
.catch((err) => { | ||
assert.deepStrictEqual( | ||
err, | ||
{ | ||
code: 404, | ||
message: 'tryUntil: max tries reached: Not a 401', | ||
name: '' | ||
} | ||
); | ||
assert.strictEqual(funcCount, 7); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -1628,0 +1729,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3195511
164
31522
36