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 3 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

5 changes: 3 additions & 2 deletions bin/can-merge
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ function outputStatus(response) {
}
});
}
console.error(`API Points: used - ${response.rateLimit.cost}\tremaining - ${response.rateLimit.remaining}`);
}

process.stderr.write(`API Points: used - ${response.rateLimit.cost}\tremaining - ${response.rateLimit.remaining}\n`);
Copy link
Owner

Choose a reason for hiding this comment

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

i think console.error should remain here; it plays more nicely with the shell output than process.stderr.write

Copy link
Contributor Author

@MaheraFurniturewala MaheraFurniturewala Mar 18, 2022

Choose a reason for hiding this comment

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

Oh ok! I think I made an error with the closing brackets as well😥


const { repo, pr, sha } = args;

const options = {
Expand Down
13 changes: 13 additions & 0 deletions utils/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ const evaluatePending = require('../utils/evaluatePending');
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?

setTimeout(() => {
process.stderr.write('.');
}, milliSecondsLeft);
Copy link
Owner

Choose a reason for hiding this comment

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

this just writes a dot, milliSecondsLeft later. it seems like maybe you want await delay(millisecondsLeft), where delay is async function delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }?

}

const isPendingChecks = evaluatePending(response);

if (!isPendingChecks) {
Expand Down