Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Auto Retry mechanism on 503? #12

Open
martinlevesque opened this issue Jun 7, 2019 · 0 comments
Open

Auto Retry mechanism on 503? #12

martinlevesque opened this issue Jun 7, 2019 · 0 comments

Comments

@martinlevesque
Copy link
Contributor

martinlevesque commented Jun 7, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants