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

fix(api): update logic of unlock api #3574

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/bot/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,27 @@ export const currentStreamTags: {
}[] = [];

let intervals = 0;
let lastIsAPIFreeKey = '';
let lastIsAPIFreeKeyRetry = 0;
let lastIsAPIFreeKey = '__unset__';
let lastIsAPIFreeKeyStart = Date.now();

const isAPIFree = (intervalList) => {
for (const key of Object.keys(intervalList)) {
if (intervalList[key].inProgress) {
if (lastIsAPIFreeKey !== key) {
lastIsAPIFreeKey = key;
lastIsAPIFreeKeyRetry = 0;
} else {
lastIsAPIFreeKeyRetry++;
lastIsAPIFreeKeyStart = Date.now();
}

// unblock if retry is more than 20 (10minutes)
if (lastIsAPIFreeKeyRetry > 20) {
if (Date.now() - lastIsAPIFreeKeyStart > 10 * constants.MINUTE) {
warning(`API call for ${key} is probably frozen (took more than 10minutes), forcefully unblocking`);
intervalList[key].inProgress = false;
lastIsAPIFreeKeyRetry = 0;
lastIsAPIFreeKey = '';
lastIsAPIFreeKey = '__unset__';
return true;
}
return false;
}
}
lastIsAPIFreeKey = '__unset__';
return true;
};

Expand Down