Skip to content

Commit

Permalink
Revert "Improve .retry() method functionality with delays and prevent…
Browse files Browse the repository at this point in the history
… calling on successful request (#1527)"

This reverts commit 62eae78.
  • Loading branch information
niftylettuce committed Jul 25, 2020
1 parent 0c4f96f commit 74641bb
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 71 deletions.
4 changes: 1 addition & 3 deletions .dist.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
}
}]
],
"plugins": [
["@babel/plugin-transform-runtime"]
]
"sourceMaps": "inline"
}
3 changes: 1 addition & 2 deletions .dist.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"no-useless-escape": "off",
"no-cond-assign": "off",
"no-redeclare": "off",
"no-fallthrough": "off",
"no-constant-condition": "off"
"node/no-exports-assign": "off"
},
"globals": {
"regeneratorRuntime": "writable"
Expand Down
4 changes: 1 addition & 3 deletions .lib.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
}
}]
],
"plugins": [
["@babel/plugin-transform-runtime"]
]
"sourceMaps": "inline"
}
9 changes: 0 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,6 @@ This method has two optional arguments: number of retries (default 1) and a call
.then(finished);
.catch(failed);

The callback supplied can be async if you need to await any data or to create a delay before retrying. This code will retry 10 times, with a 3 second delay between each retry. To add a delay:

.retry(10, async function(err, res) {
let delay = 3000; // ms
log.error(`Request failed, retrying in ${delay / 1000} seconds ...`);
await new Promise(resolve => setTimeout(() => resolve(), delay));
return true;
})

Use `.retry()` only with requests that are *idempotent* (i.e. multiple requests reaching the server won't cause undesirable side effects like duplicate purchases).

## Setting Accept
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"Nick Baugh <[email protected]>"
],
"dependencies": {
"@babel/runtime": "7.4.5",
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.2",
"debug": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ Request.prototype._getFormData = function() {
* @api private
*/

Request.prototype.callback = async function(err, res) {
if (err !== null && (await this._shouldRetry(err, res))) {
Request.prototype.callback = function(err, res) {
if (this._shouldRetry(err, res)) {
return this._retry();
}

Expand Down
4 changes: 2 additions & 2 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ Request.prototype.request = function() {
* @api private
*/

Request.prototype.callback = async function(err, res) {
if (err !== null && (await this._shouldRetry(err, res))) {
Request.prototype.callback = function(err, res) {
if (this._shouldRetry(err, res)) {
return this._retry();
}

Expand Down
4 changes: 2 additions & 2 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ const ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EADDRINFO', 'ESOCKETTIMEDOUT'];
* @param {Response} [res] response
* @returns {Boolean} if segment should be retried
*/
RequestBase.prototype._shouldRetry = async function(err, res) {
RequestBase.prototype._shouldRetry = function(err, res) {
if (!this._maxRetries || this._retries++ >= this._maxRetries) {
return false;
}

if (this._retryCallback) {
try {
const override = await this._retryCallback(err, res);
const override = this._retryCallback(err, res);
if (override === true) return true;
if (override === false) return false;
// undefined falls back to defaults
Expand Down
92 changes: 45 additions & 47 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,6 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"

"@babel/[email protected]":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
integrity sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ==
dependencies:
regenerator-runtime "^0.13.2"

"@babel/runtime@^7.8.4", "@babel/runtime@^7.9.6":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.5.tgz#303d8bd440ecd5a491eae6117fd3367698674c5c"
Expand Down Expand Up @@ -1047,9 +1040,9 @@
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/node@*":
version "14.0.23"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806"
integrity sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw==
version "14.0.26"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.26.tgz#22a3b8a46510da8944b67bfc27df02c34a35331c"
integrity sha512-W+fpe5s91FBGE0pEa0lnqGLL4USgpLgs4nokw16SrBBco/gQxuua7KnArSEOd5iaMqbbSHV10vUDkJYJJqpXKA==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -2235,14 +2228,14 @@ camelcase@^6.0.0:
integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w==

caniuse-db@^1.0.30001090:
version "1.0.30001102"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001102.tgz#28e7da3f2969781728a0f50119a7aca179bf9e72"
integrity sha512-VUH/Ch7IaLSmugVKMTQEJlvSUAezLQY0uo1OZ6TJryWDln5vt/QrJjj+h/fVTuhUfYFc4pqfIc0u9ENn+vUy/g==
version "1.0.30001105"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001105.tgz#5cc03239a9d4540b3fa9a1dc8b5e3bda50226e96"
integrity sha512-GZytZn8lOiru/Tw+/X5sFxrFt2uPdSvkxVKzRMJyX20JGwfwOuTiRg5IMVF9II8Lao/7C4YeHR8YnZzpTvYXdQ==

caniuse-lite@^1.0.30001093:
version "1.0.30001102"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001102.tgz#3275e7a8d09548f955f665e532df88de0b63741a"
integrity sha512-fOjqRmHjRXv1H1YD6QVLb96iKqnu17TjcLSaX64TwhGYed0P1E1CCWZ9OujbbK4Z/7zax7zAzvQidzdtjx8RcA==
version "1.0.30001105"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001105.tgz#d2cb0b31e5cf2f3ce845033b61c5c01566549abf"
integrity sha512-JupOe6+dGMr7E20siZHIZQwYqrllxotAhiaej96y6x00b/48rPt42o+SzOSCPbrpsDWvRja40Hwrj0g0q6LZJg==

caseless@~0.6.0:
version "0.6.0"
Expand Down Expand Up @@ -2454,9 +2447,9 @@ [email protected]:
integrity sha1-TqVOpaCJOBUxheFSEMaNkJK8G3g=

codecov@^3.7.0:
version "3.7.1"
resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.7.1.tgz#434cb8d55f18ef01672e5739d3d266696bebc202"
integrity sha512-JHWxyPTkMLLJn9SmKJnwAnvY09kg2Os2+Ux+GG7LwZ9g8gzDDISpIN5wAsH1UBaafA/yGcd3KofMaorE8qd6Lw==
version "3.7.2"
resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.7.2.tgz#998e68c8c1ef4b55cfcf11cd456866d35e13d693"
integrity sha512-fmCjAkTese29DUX3GMIi4EaKGflHa4K51EoMc29g8fBHawdk/+KEq5CWOeXLdd9+AT7o1wO4DIpp/Z1KCqCz1g==
dependencies:
argv "0.0.2"
ignore-walk "3.0.3"
Expand Down Expand Up @@ -3334,9 +3327,9 @@ [email protected]:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.488:
version "1.3.499"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.499.tgz#06949f19877dafa42915e57dfeb4c1cfb86a8649"
integrity sha512-y7FwtQm/8xuLMnYQfBQDYzCpNn+VkSnf4c3Km5TWMNXg7JA5RQBuxmcLaKdDVcIK0K5xGIa7TlxpRt4BdNxNoA==
version "1.3.509"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.509.tgz#830fcb89cd66dc2984d18d794973b99e3f00584c"
integrity sha512-cN4lkjNRuTG8rtAqTOVgwpecEC2kbKA04PG6YijcKGHK/kD0xLjiqExcAOmLUwtXZRF8cBeam2I0VZcih919Ug==

elliptic@^6.0.0, elliptic@^6.5.2:
version "6.5.3"
Expand Down Expand Up @@ -3767,9 +3760,9 @@ eslint-plugin-unicorn@^12.0.0:
semver "^6.3.0"

eslint-rule-docs@^1.1.5:
version "1.1.199"
resolved "https://registry.yarnpkg.com/eslint-rule-docs/-/eslint-rule-docs-1.1.199.tgz#f4e0befb6907101399624964ce4726f684415630"
integrity sha512-0jXhQ2JLavUsV/8HVFrBSHL4EM17cl0veZHAVcF1HOEoPdrr09huADK9/L7CbsqP4tMJy9FG23neUEDH8W/Mmg==
version "1.1.200"
resolved "https://registry.yarnpkg.com/eslint-rule-docs/-/eslint-rule-docs-1.1.200.tgz#6de559326ff08f87d319f86daee0b26430150f19"
integrity sha512-3j5+8OVAWepxOZuLijXhqzWFPzD02CqxAP0hnHj1+s6PgTFmSmpaAtwPfv6BZg8NHGxLVS3AD0MIXJIwfn5ypQ==

eslint-scope@^5.0.0:
version "5.1.0"
Expand Down Expand Up @@ -5284,17 +5277,17 @@ inline-source-map@~0.6.0:
source-map "~0.5.3"

inquirer@^7.0.0:
version "7.3.2"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.2.tgz#25245d2e32dc9f33dbe26eeaada231daa66e9c7c"
integrity sha512-DF4osh1FM6l0RJc5YWYhSDB6TawiBRlbV9Cox8MWlidU218Tb7fm3lQTULyUJDfJ0tjbzl0W4q651mrCCEM55w==
version "7.3.3"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003"
integrity sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA==
dependencies:
ansi-escapes "^4.2.1"
chalk "^4.1.0"
cli-cursor "^3.1.0"
cli-width "^3.0.0"
external-editor "^3.0.3"
figures "^3.0.0"
lodash "^4.17.16"
lodash "^4.17.19"
mute-stream "0.0.8"
run-async "^2.4.0"
rxjs "^6.6.0"
Expand Down Expand Up @@ -6094,9 +6087,9 @@ lint-staged@^10.2.11:
stringify-object "^3.3.0"

listr2@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/listr2/-/listr2-2.2.0.tgz#cb88631258abc578c7fb64e590fe5742f28e4aac"
integrity sha512-Q8qbd7rgmEwDo1nSyHaWQeztfGsdL6rb4uh7BA+Q80AZiDET5rVntiU1+13mu2ZTDVaBVbvAD1Db11rnu3l9sg==
version "2.3.3"
resolved "https://registry.yarnpkg.com/listr2/-/listr2-2.3.3.tgz#ee9f4d95dd325ad1ae89fe7327f2a4f4498224b5"
integrity sha512-vU2eiFEzUEaDjgwRJ/n8RB79K2cBcaTw1DigIGHnXGp/BEeQqxGwiM8R17Itit5l2ykrrST11kw2l9vSpCbqUQ==
dependencies:
chalk "^4.0.0"
cli-truncate "^2.1.0"
Expand Down Expand Up @@ -6370,7 +6363,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=

lodash@^4.13.1, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.16, lodash@^4.17.19:
lodash@^4.13.1, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
Expand Down Expand Up @@ -6607,9 +6600,9 @@ mdast-util-toc@^5.0.0:
unist-util-visit "^2.0.0"

mdn-browser-compat-data@^1.0.28:
version "1.0.31"
resolved "https://registry.yarnpkg.com/mdn-browser-compat-data/-/mdn-browser-compat-data-1.0.31.tgz#4bc736252fafcafc182f9dd43b105d6795b9a28e"
integrity sha512-GVQQYWgoH3jbBaIy8M4hrg34qaNpPedtZvwAjUmkpHq4FXKKCea8Ji5rlS32YJSU9dt7TPvuWWX7Cce5mZyFPA==
version "1.0.32"
resolved "https://registry.yarnpkg.com/mdn-browser-compat-data/-/mdn-browser-compat-data-1.0.32.tgz#05bdf6b8d49c55a5a2a1c370b68e169300abf56d"
integrity sha512-dqIstpk2ysqa6XcI8/fz1yB6bOKrIs61RIEE00Dj7+WHReXlGrCIiol1NBPsLUNE+HC/4y2f8va8vy1WsiCkAQ==
dependencies:
extend "3.0.2"

Expand Down Expand Up @@ -7200,9 +7193,9 @@ node-preload@^0.2.1:
process-on-spawn "^1.0.0"

node-releases@^1.1.58:
version "1.1.59"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.59.tgz#4d648330641cec704bff10f8e4fe28e453ab8e8e"
integrity sha512-H3JrdUczbdiwxN5FuJPyCHnGHIFqQ0wWxo+9j1kAXAzqNMAHlo+4I/sYYxpyK0irQ73HgdiyzD32oqQDcU2Osw==
version "1.1.60"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084"
integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==

node-uuid@~1.4.0, node-uuid@~1.4.1:
version "1.4.8"
Expand Down Expand Up @@ -7676,9 +7669,9 @@ parse-json@^4.0.0:
json-parse-better-errors "^1.0.1"

parse-json@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.0.0.tgz#73e5114c986d143efa3712d4ea24db9a4266f60f"
integrity sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw==
version "5.0.1"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.0.1.tgz#7cfe35c1ccd641bce3981467e6c2ece61b3b3878"
integrity sha512-ztoZ4/DYeXQq4E21v169sC8qWINGpcosGv9XhTDvg9/hWvx/zrFkc9BiWxR58OJLHGk28j5BL0SDLeV2WmFZlQ==
dependencies:
"@babel/code-frame" "^7.0.0"
error-ex "^1.3.1"
Expand Down Expand Up @@ -8279,11 +8272,16 @@ regenerate@^1.4.0:
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.1.tgz#cad92ad8e6b591773485fbe05a485caf4f457e6f"
integrity sha512-j2+C8+NtXQgEKWk49MMP5P/u2GhnahTtVkRIHr5R5lVRlbKvmQ+oS+A5aLKWp2ma5VkT8sh6v+v4hbH0YHR66A==

[email protected], regenerator-runtime@^0.13.2, regenerator-runtime@^0.13.4:
[email protected]:
version "0.13.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==

regenerator-runtime@^0.13.4:
version "0.13.7"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==

regenerator-transform@^0.14.2:
version "0.14.5"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.5.tgz#c98da154683671c9c4dcb16ece736517e1b7feb4"
Expand Down Expand Up @@ -8416,7 +8414,7 @@ remark-heading-gap@^3.1.2:
resolved "https://registry.yarnpkg.com/remark-heading-gap/-/remark-heading-gap-3.1.2.tgz#480b71a655e793848db42b714358b5533d7d5ec3"
integrity sha512-LNm1B4UveH1BkSLx4OPab0vW/p3KOc+8wV4kd94CHXmhuJ8i+kdroG2AonkUVzbOElc8U8ylxF3WPfmqYbRjJg==

remark-license@niftylettuce/remark-license:
"remark-license@github:niftylettuce/remark-license":
version "4.0.1"
resolved "https://codeload.github.com/niftylettuce/remark-license/tar.gz/17ecb8f64f8f6082414d14f9267a12764e6ddbfb"
dependencies:
Expand Down Expand Up @@ -10759,9 +10757,9 @@ unified-message-control@^3.0.0:
vfile-location "^3.0.0"

unified@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/unified/-/unified-9.0.0.tgz#12b099f97ee8b36792dbad13d278ee2f696eed1d"
integrity sha512-ssFo33gljU3PdlWLjNp15Inqb77d6JnJSfyplGJPT/a+fNRNyCBeveBAYJdO5khKdF6WVHa/yYCC7Xl6BDwZUQ==
version "9.1.0"
resolved "https://registry.yarnpkg.com/unified/-/unified-9.1.0.tgz#7ba82e5db4740c47a04e688a9ca8335980547410"
integrity sha512-VXOv7Ic6twsKGJDeZQ2wwPqXs2hM0KNu5Hkg9WgAZbSD1pxhZ7p8swqg583nw1Je2fhwHy6U8aEjiI79x1gvag==
dependencies:
bail "^1.0.0"
extend "^3.0.0"
Expand Down

0 comments on commit 74641bb

Please sign in to comment.