Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rerun

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rerun - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

6

package.json
{
"name": "rerun",
"description": "A retry library for node.js",
"version": "1.1.2",
"version": "1.1.3",
"author": "BigPanda <noam@bigpanda.io>",

@@ -17,4 +17,4 @@ "repository": {

"dependencies": {
"q": "~1.0.0",
"request": "~2.33.0"
"q": "1.0.1",
"request": "2.36.0"
},

@@ -21,0 +21,0 @@ "main": "./src/index.js",

@@ -1,2 +0,35 @@

retry
rerun
=====
A retry library for node.js.<br/>
Rerun supports promises and request.js, as you will see, the API is pretty simple.
The options and their defaults for rerun library are:
```javascript
{
retries: 3
retryTimeout: 50
retryFactor: 1
}
```
* `retries` - How many times to retry before failing.
* `retryTimeout` - The initial time to wait (in milliseconds) before each retry.
* `retryFactor` - The multiplier after each fail to multiply `retryTimeout` with.
Request
-------
Rerun use with request is the same as with request itself, but with promises.
```javascript
var request = require('rerun').request;
var promise = request({method:'POST', url: 'http://localhost/test', retries: 2, retryTimeout: 10, retryFactor: 2});
```
Promise
-------
Rerun with promises is easy too, all you need is to call the library with the function you want to retry, and if it fails, the library will try again.<br/>
Notice that if you don't want the library to retry, you can throw `require('rerun').RejectError`.
```javascript
var retry = require('rerun').promise;
var promise = retry(function () { doSomething(); }, { retries: 2, retryTimeout: 10, retryFactor: 2 });
```

@@ -7,5 +7,7 @@ var chai = require('chai');

var request = retry.request;
var Q = require('q');
describe('Retry tests', function () {
it('should fail after four tries', function (done) {
it('should fail after four tries', function () {
var id = { complicated: 'id' };

@@ -20,11 +22,11 @@ var data = [

var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 4, method: 'POST' });
promise.then(function () {
done(new Error('should fail'));
}, function () {
return promise.then(function () {
return Q.reject(new Error('should fail'));
}, function (err) {
scope.done();
done();
return Q();
});
});
it('should succeed after two tries', function (done) {
it('should succeed after two tries', function () {
var id = { complicated: 'id' };

@@ -39,10 +41,6 @@ var data = [

nock('http://localhost:3027').post('/test', JSON.stringify({ objects: array })).reply(200);
var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 4, method: 'POST' });
promise.then(function () {
done();
}, function (error) {
done(error);
});
return request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 4, method: 'POST' });
});
it('should not retry on user error', function (done) {
it('should not retry on user error', function () {
var id = { complicated: 'id' };

@@ -57,11 +55,11 @@ var data = [

var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 3, method: 'POST' });
promise.then(function () {
done(new Error('Should fail'));
return promise.then(function () {
Q.reject(new Error('Should fail'));
}, function () {
scope.done();
done();
return Q();
});
});
it('should not retry even if rejecterror is defined weird', function (done) {
it('should not retry even if rejecterror is defined weird', function () {
var id = { complicated: 'id' };

@@ -76,11 +74,11 @@ var data = [

var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 3, method: 'POST', rejectError: undefined });
promise.then(function () {
done(new Error('Should fail'));
return promise.then(function () {
return Q.reject(new Error('Should fail'));
}, function () {
scope.done();
done();
return Q();
});
});
it('should not retry even if rejecterror is defined', function (done) {
it('should not retry even if rejecterror is defined', function () {
var id = { complicated: 'id' };

@@ -95,11 +93,11 @@ var data = [

var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 3, method: 'POST', rejectError: require('../../src/promise') });
promise.then(function () {
done(new Error('Should fail'));
return promise.then(function () {
return Q.reject(new Error('Should fail'));
}, function () {
scope.done();
done();
return Q();
});
});
it('should wait exponential time', function (done) {
it('should wait exponential time', function () {
var id = { complicated: 'id' };

@@ -112,12 +110,9 @@ var data = [

];
nock('http://localhost:3027').post('/test', JSON.stringify({ objects: array })).times(4).reply(401);
var scope = nock('http://localhost:3027').post('/test', JSON.stringify({ objects: array })).reply(200);
var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 5, retryFactor: 2, retryTimeout: 10, method: 'POST' });
nock('http://localhost:3027').post('/test1', JSON.stringify({ objects: array })).times(4).reply(401);
var scope = nock('http://localhost:3027').post('/test1', JSON.stringify({ objects: array })).reply(200);
var promise = request({ url: 'http://localhost:3027/test1', json: { objects: array }, retries: 5, retryFactor: 2, retryTimeout: 10, method: 'POST' });
var timeBefore = new Date().getTime();
promise.then(function () {
return promise.then(function () {
expect(new Date().getTime() - timeBefore).to.lte(170).and.to.gte(130);
scope.done();
done();
}, function (err) {
done(err);
});

@@ -127,3 +122,3 @@ });

it('should randomize time', function (done) {
it('should randomize time', function () {
var id = { complicated: 'id' };

@@ -140,10 +135,7 @@ var data = [

var timeBefore = new Date().getTime();
promise.then(function () {
return promise.then(function () {
expect(new Date().getTime() - timeBefore).to.lte(200).and.to.gte(100);
scope.done();
done();
}, function (err) {
done(err);
}).done();
})
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc