update
This commit is contained in:
19
package/node_modules/promise-retry/LICENSE
generated
vendored
Normal file
19
package/node_modules/promise-retry/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 IndigoUnited
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
52
package/node_modules/promise-retry/index.js
generated
vendored
Normal file
52
package/node_modules/promise-retry/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var errcode = require('err-code');
|
||||
var retry = require('retry');
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
function isRetryError(err) {
|
||||
return err && err.code === 'EPROMISERETRY' && hasOwn.call(err, 'retried');
|
||||
}
|
||||
|
||||
function promiseRetry(fn, options) {
|
||||
var temp;
|
||||
var operation;
|
||||
|
||||
if (typeof fn === 'object' && typeof options === 'function') {
|
||||
// Swap options and fn when using alternate signature (options, fn)
|
||||
temp = options;
|
||||
options = fn;
|
||||
fn = temp;
|
||||
}
|
||||
|
||||
operation = retry.operation(options);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
operation.attempt(function (number) {
|
||||
Promise.resolve()
|
||||
.then(function () {
|
||||
return fn(function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
}
|
||||
|
||||
throw errcode(new Error('Retrying'), 'EPROMISERETRY', { retried: err });
|
||||
}, number);
|
||||
})
|
||||
.then(resolve, function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
|
||||
if (operation.retry(err || new Error())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = promiseRetry;
|
37
package/node_modules/promise-retry/package.json
generated
vendored
Normal file
37
package/node_modules/promise-retry/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "promise-retry",
|
||||
"version": "2.0.1",
|
||||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha --bail -t 10000"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/IndigoUnited/node-promise-retry/issues/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/IndigoUnited/node-promise-retry.git"
|
||||
},
|
||||
"keywords": [
|
||||
"retry",
|
||||
"promise",
|
||||
"backoff",
|
||||
"repeat",
|
||||
"replay"
|
||||
],
|
||||
"author": "IndigoUnited <hello@indigounited.com> (http://indigounited.com)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"mocha": "^8.0.1",
|
||||
"sleep-promise": "^8.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"err-code": "^2.0.2",
|
||||
"retry": "^0.12.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
}
|
263
package/node_modules/promise-retry/test/test.js
generated
vendored
Normal file
263
package/node_modules/promise-retry/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var promiseRetry = require('../');
|
||||
var promiseDelay = require('sleep-promise');
|
||||
|
||||
describe('promise-retry', function () {
|
||||
it('should call fn again if retry was called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should call fn with the attempt number', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry, number) {
|
||||
count += 1;
|
||||
expect(count).to.equal(number);
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on fulfillment if retry was not called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function () {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
return 'final';
|
||||
});
|
||||
})
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(1);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on rejection if retry was not called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function () {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on rejection if nr of retries is 0', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
})
|
||||
.catch(retry);
|
||||
}, { retries : 0 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject the promise if the retries were exceeded', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
})
|
||||
.catch(retry);
|
||||
}, { retries: 2, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass options to the underlying retry module', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count < 2) {
|
||||
count += 1;
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert direct fulfillments into promises', function () {
|
||||
return promiseRetry(function () {
|
||||
return 'final';
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert direct rejections into promises', function () {
|
||||
promiseRetry(function () {
|
||||
throw new Error('foo');
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash on undefined rejections', function () {
|
||||
return promiseRetry(function () {
|
||||
throw undefined;
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err).to.be(undefined);
|
||||
})
|
||||
.then(function () {
|
||||
return promiseRetry(function (retry) {
|
||||
retry();
|
||||
}, { retries: 1, factor: 1 });
|
||||
})
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('should retry if retry() was called with undefined', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry();
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with several retries in the same chain', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
retry(new Error('foo'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
retry(err);
|
||||
});
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow options to be passed first', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry({ factor: 1 }, function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}).then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user