added random retry times

This commit is contained in:
Philipp Kunz 2017-01-29 17:42:15 +01:00
parent 8a8adb48c6
commit 803f1ce41a
4 changed files with 21 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ describe('cflare', function () {
describe('.CflareAccount', function () { describe('.CflareAccount', function () {
describe('.listZones()', function () { describe('.listZones()', function () {
it('should display an entire account', function (done) { it('should display an entire account', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.listZones() testCflareAccount.listZones()
.then((responseArg) => { .then((responseArg) => {
done(); done();
@ -22,7 +22,7 @@ describe('cflare', function () {
}); });
describe('.getZoneId(domainName)', function () { describe('.getZoneId(domainName)', function () {
it('should get an Cloudflare Id for a domain string', function (done) { it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.getZoneId('bleu.de') testCflareAccount.getZoneId('bleu.de')
.then((responseArg) => { .then((responseArg) => {
done(); done();
@ -31,7 +31,7 @@ describe('cflare', function () {
}); });
describe('.listRecords(domainName)', function () { describe('.listRecords(domainName)', function () {
it('should list all records for a specific Domain Name', function (done) { it('should list all records for a specific Domain Name', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.listRecords('bleu.de') testCflareAccount.listRecords('bleu.de')
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg); console.log(responseArg);
@ -41,14 +41,14 @@ describe('cflare', function () {
}); });
describe('.createRecord', function () { describe('.createRecord', function () {
it('should create a valid record for a level 2 domain', function (done) { it('should create a valid record for a level 2 domain', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1') testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1')
.then(function (responseArg) { .then(function (responseArg) {
done(); done();
}); });
}); });
it('should create a valid record for a subdomain', function (done) { it('should create a valid record for a subdomain', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1') testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1')
.then(function (responseArg) { .then(function (responseArg) {
done(); done();
@ -57,7 +57,7 @@ describe('cflare', function () {
}); });
describe('.getRecord', function () { describe('.getRecord', function () {
it('should get a record from Cloudflare', function (done) { it('should get a record from Cloudflare', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.getRecord('bleu.de', 'A') testCflareAccount.getRecord('bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg); console.log(responseArg);
@ -67,7 +67,7 @@ describe('cflare', function () {
}); });
describe('.removeRecord', function () { describe('.removeRecord', function () {
it('should remove a record from Cloudflare', function (done) { it('should remove a record from Cloudflare', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.removeRecord('bleu.de', 'A') testCflareAccount.removeRecord('bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg); console.log(responseArg);
@ -75,7 +75,7 @@ describe('cflare', function () {
}); });
}); });
it('should remove a subdomain record from Cloudflare', function (done) { it('should remove a subdomain record from Cloudflare', function (done) {
this.timeout(30000); this.timeout(60000);
testCflareAccount.removeRecord('subdomain.bleu.de', 'A') testCflareAccount.removeRecord('subdomain.bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg); console.log(responseArg);

View File

@ -14,7 +14,7 @@ describe('cflare', function () {
describe('.CflareAccount', function () { describe('.CflareAccount', function () {
describe('.listZones()', function () { describe('.listZones()', function () {
it('should display an entire account', function (done) { it('should display an entire account', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.listZones() testCflareAccount.listZones()
.then((responseArg) => { .then((responseArg) => {
done() done()
@ -23,7 +23,7 @@ describe('cflare', function () {
}) })
describe('.getZoneId(domainName)', function () { describe('.getZoneId(domainName)', function () {
it('should get an Cloudflare Id for a domain string', function (done) { it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.getZoneId('bleu.de') testCflareAccount.getZoneId('bleu.de')
.then((responseArg) => { .then((responseArg) => {
done() done()
@ -32,7 +32,7 @@ describe('cflare', function () {
}) })
describe('.listRecords(domainName)', function () { describe('.listRecords(domainName)', function () {
it('should list all records for a specific Domain Name', function (done) { it('should list all records for a specific Domain Name', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.listRecords('bleu.de') testCflareAccount.listRecords('bleu.de')
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg) console.log(responseArg)
@ -42,14 +42,14 @@ describe('cflare', function () {
}) })
describe('.createRecord', function () { describe('.createRecord', function () {
it('should create a valid record for a level 2 domain', function (done) { it('should create a valid record for a level 2 domain', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1') testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1')
.then(function (responseArg) { .then(function (responseArg) {
done() done()
}) })
}) })
it('should create a valid record for a subdomain', function (done) { it('should create a valid record for a subdomain', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1') testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1')
.then(function (responseArg) { .then(function (responseArg) {
done() done()
@ -58,7 +58,7 @@ describe('cflare', function () {
}) })
describe('.getRecord', function () { describe('.getRecord', function () {
it('should get a record from Cloudflare', function (done) { it('should get a record from Cloudflare', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.getRecord('bleu.de', 'A') testCflareAccount.getRecord('bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg) console.log(responseArg)
@ -68,7 +68,7 @@ describe('cflare', function () {
}) })
describe('.removeRecord', function () { describe('.removeRecord', function () {
it('should remove a record from Cloudflare', function (done) { it('should remove a record from Cloudflare', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.removeRecord('bleu.de', 'A') testCflareAccount.removeRecord('bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg) console.log(responseArg)
@ -76,7 +76,7 @@ describe('cflare', function () {
}) })
}) })
it('should remove a subdomain record from Cloudflare', function (done) { it('should remove a subdomain record from Cloudflare', function (done) {
this.timeout(30000) this.timeout(60000)
testCflareAccount.removeRecord('subdomain.bleu.de', 'A') testCflareAccount.removeRecord('subdomain.bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg) console.log(responseArg)

View File

@ -137,13 +137,11 @@ export class CflareAccount {
console.log('rate limited! Waiting for retry!') console.log('rate limited! Waiting for retry!')
retryRequest() retryRequest()
} else { } else {
console.log(response.status) console.log(response.statusCode)
console.log(response.messages)
console.log(response.errors)
done.reject(new Error('request failed')) done.reject(new Error('request failed'))
} }
} }
let retryRequest = async (delayTimeArg = 6000) => { let retryRequest = async (delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)) => {
console.log(`retry started and waiting for ${delayTimeArg} ms`) console.log(`retry started and waiting for ${delayTimeArg} ms`)
await plugins.smartdelay.delayFor(delayTimeArg) await plugins.smartdelay.delayFor(delayTimeArg)
if (retryCount < 10) { if (retryCount < 10) {