Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the rate limit exceeding error #71

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/mocks/* -diff linguist-generated=true

17 changes: 17 additions & 0 deletions utils/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

const evaluatePending = require('../utils/evaluatePending');

async function delay(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

module.exports = async function watch(retryDelay, getResponse) {
const response = await getResponse();

const { remaining: remAPIPoints, cost: lastReqCost, resetAt } = response.rateLimit;
const currentTime = new Date();
const resetTime = new Date(resetAt);
const milliSecondsLeft = resetTime - currentTime;
const secondsLeft = Math.ceil(milliSecondsLeft / 1000);

if ((remAPIPoints < lastReqCost) && (retryDelay < milliSecondsLeft)) {
process.stderr.write(`API points exhausted. Command will run after ${secondsLeft} seconds\n\n`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's going to write a newline, can it use console.error?

await delay(milliSecondsLeft);
}

const isPendingChecks = evaluatePending(response);

if (!isPendingChecks) {
Expand Down