fix: recursion of JaxRequest now works if we receive 500/503

This commit is contained in:
Valentin Kaelin 2019-10-21 20:05:17 +02:00
parent 668930d7ca
commit d698057fae

View file

@ -1,9 +1,13 @@
const { promisify } = require('util')
class JaxRequest { class JaxRequest {
constructor(config, endpoint, limiter) { constructor(config, endpoint, limiter) {
this.config = config this.config = config
this.endpoint = endpoint this.endpoint = endpoint
this.limiter = limiter this.limiter = limiter
this.retries = config.requestOptions.retriesBeforeAbort this.retries = config.requestOptions.retriesBeforeAbort
this.sleep = promisify(setTimeout)
} }
async execute() { async execute() {
@ -26,10 +30,8 @@ class JaxRequest {
console.log('====================================') console.log('====================================')
if (this.retries > 0) { if (this.retries > 0) {
return setTimeout( await this.sleep(this.config.requestOptions.delayBeforeRetry)
() => this.execute(), return this.execute()
this.config.requestOptions.delayBeforeRetry,
)
} }
} }