node-vultr
node-vultr copied to clipboard
Auto Retry mechanism on 503?
Don't know if this could be included as an option feature, I added the following function (query) to add a retry mechanism:
async function wait(seconds) {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, seconds * 1000);
});
}
vultrInstance.query = async function(category, func, ...params) {
for (let retry = 0; retry <= 7; ++retry) { // max trials
try {
return await vultrInstance[category][func](...params);
} catch(err) {
if (err.statusCode !== 503) {
throw err;
} else {
await wait(2);
}
}
}
}
but perhaps could be interesting to have it as an option instead of the default 1 second timeout before the request.