Gathering detailed insights and metrics for retry-request
Gathering detailed insights and metrics for retry-request
Gathering detailed insights and metrics for retry-request
Gathering detailed insights and metrics for retry-request
**THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024** Retry a request with built-in exponential backoff.
npm install retry-request
52.1
Supply Chain
97.3
Quality
78.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
67 Stars
178 Commits
16 Forks
47 Watching
10 Branches
232 Contributors
Updated on 23 Oct 2024
Minified
Minified + Gzipped
JavaScript (96.89%)
Python (3.11%)
Cumulative downloads
Total Downloads
Last day
-10.7%
1,276,928
Compared to previous day
Last week
2.1%
7,522,563
Compared to previous week
Last month
8.2%
31,710,699
Compared to previous month
Last year
52.1%
324,958,205
Compared to previous year
3
THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024. RELEVANT FUNCTIONALITIES HAVE BEEN MOVED TO GOOGLEAPIS/GAXIOS
Retry a request with built-in exponential backoff. |
1$ npm install --save teeny-request 2$ npm install --save retry-request
1var request = require('retry-request', { 2 request: require('teeny-request'), 3});
It should work the same as request
and teeny-request
in both callback mode and stream mode.
Note: This module only works when used as a readable stream, i.e. POST requests aren't supported (#3).
request
?Yes! You must independently install teeny-request
OR request
(deprecated) and provide it to this library:
1var request = require('retry-request', { 2 request: require('teeny-request'), 3});
urlThatReturns503
will be requested 3 total times before giving up and executing the callback.
1request(urlThatReturns503, function (err, resp, body) {});
urlThatReturns503
will be requested 3 total times before giving up and emitting the response
and complete
event as usual.
1request(urlThatReturns503) 2 .on('error', function () {}) 3 .on('response', function () {}) 4 .on('complete', function () {});
Yes! To enable the debug mode, set the environment variable DEBUG
to retry-request.
(Thanks for the implementation, @yihaozhadan!)
Passed directly to request
or teeny-request
. See the list of options supported:
opts.noResponseRetries
Type: Number
Default: 2
The number of times to retry after a response fails to come through, such as a DNS resolution error or a socket hangup.
1var opts = { 2 noResponseRetries: 0, 3}; 4 5request(url, opts, function (err, resp, body) { 6 // url was requested 1 time before giving up and 7 // executing this callback. 8});
opts.objectMode
Type: Boolean
Default: false
Set to true
if your custom opts.request
function returns a stream in object mode.
opts.retries
Type: Number
Default: 2
1var opts = { 2 retries: 4, 3}; 4 5request(urlThatReturns503, opts, function (err, resp, body) { 6 // urlThatReturns503 was requested a total of 5 times 7 // before giving up and executing this callback. 8});
opts.currentRetryAttempt
Type: Number
Default: 0
1var opts = { 2 currentRetryAttempt: 1, 3}; 4 5request(urlThatReturns503, opts, function (err, resp, body) { 6 // urlThatReturns503 was requested as if it already failed once. 7});
opts.shouldRetryFn
Type: Function
Default: Returns true
if http.incomingMessage.statusCode is < 200 or >= 400.
1var opts = { 2 shouldRetryFn: function (incomingHttpMessage) { 3 return incomingHttpMessage.statusMessage !== 'OK'; 4 }, 5}; 6 7request(urlThatReturnsNonOKStatusMessage, opts, function (err, resp, body) { 8 // urlThatReturnsNonOKStatusMessage was requested a 9 // total of 3 times, each time using `opts.shouldRetryFn` 10 // to decide if it should continue before giving up and 11 // executing this callback. 12});
opts.request
Type: Function
If we not provided we will throw an error advising you to provide it.
NOTE: If you override the request function, and it returns a stream in object mode, be sure to set opts.objectMode
to true
.
1var originalRequest = require('teeny-request').defaults({ 2 pool: { 3 maxSockets: Infinity, 4 }, 5}); 6 7var opts = { 8 request: originalRequest, 9}; 10 11request(urlThatReturns503, opts, function (err, resp, body) { 12 // Your provided `originalRequest` instance was used. 13});
opts.maxRetryDelay
Type: Number
Default: 64
The maximum time to delay in seconds. If retryDelayMultiplier results in a delay greater than maxRetryDelay, retries should delay by maxRetryDelay seconds instead.
opts.retryDelayMultiplier
Type: Number
Default: 2
The multiplier by which to increase the delay time between the completion of failed requests, and the initiation of the subsequent retrying request.
opts.totalTimeout
Type: Number
Default: 600
The length of time to keep retrying in seconds. The last sleep period will be shortened as necessary, so that the last retry runs at deadline (and not considerably beyond it). The total time starting from when the initial request is sent, after which an error will be returned, regardless of the retrying attempts made meanwhile.
Passed directly to request
. See the callback section: https://github.com/request/request/#requestoptions-callback.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 16/17 approved changesets -- score normalized to 9
Reason
SAST tool is not run on all commits -- score normalized to 4
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More