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

Auto Retry mechanism on 503? #12

Description

@martinlevesque

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions