Skip to content

Commit

Permalink
chore: Prevent marking licenses as processed when rate limit is exceeded
Browse files Browse the repository at this point in the history
This change ensures that licenses resulting in a `RateLimitExceeded` status are not added to the `processedLicenses` file.

- Added a check in the `checkGame` function to detect if any bot encounters a `RateLimitExceeded` status.
- If a rate limit is detected, the license is not marked as processed, allowing it to be retried in the next run.
- Logs an error and sends a webhook notification when a rate limit is encountered.
- Licenses without rate limit issues are processed and marked as completed as usual.

This prevents premature marking of licenses as processed when ASF is unable to handle them due to rate limits, ensuring they are retried in subsequent runs.
  • Loading branch information
JourneyOver committed Feb 9, 2025
1 parent 9d80ca0 commit ffac538
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,30 @@ async function checkGame() {
.then(async res => res.json())
.then(async body => {
if (body.Success) {
console.log(`Success: License Added`);
console.log(`Command: !addlicense ${args.bots} ${currentPack}`);
console.log(`Result: ${body.Result.trim()}`);
console.log(`Message: ${body.Message}`);
console.log(`Success: ✅`);
console.log(`----------------------------------`);
processedLicenses.push(currentPack); // Add to processed list
saveProcessedLicenses(); // Save to file
if (args.hookShowAccountStatus === "true") {
await sendHookAsync("success", "Processed a new package!", currentPack, parseASFResult(body.Result));
const asfResultObj = parseASFResult(body.Result);
const hasRateLimit = Object.values(asfResultObj).some(result => result.status.includes('RateLimitExceeded'));

if (hasRateLimit) {
console.error("Rate limit exceeded, not marking as processed.");
console.log(`Command: !addlicense ${args.bots} ${currentPack}`);
console.log(`Result: ${body.Result.trim()}`);
console.log(`Message: ${body.Message}`);
console.log(`----------------------------------`);
await sendHookAsync("error", "Rate limit exceeded while processing package. Will retry in next run.", currentPack, asfResultObj);
} else {
await sendHookAsync("success", "Processed a new package!", currentPack);
console.log(`Success: License Added`);
console.log(`Command: !addlicense ${args.bots} ${currentPack}`);
console.log(`Result: ${body.Result.trim()}`);
console.log(`Message: ${body.Message}`);
console.log(`Success: ✅`);
console.log(`----------------------------------`);
processedLicenses.push(currentPack); // Add to processed list
saveProcessedLicenses(); // Save to file
if (args.hookShowAccountStatus === "true") {
await sendHookAsync("success", "Processed a new package!", currentPack, asfResultObj);
} else {
await sendHookAsync("success", "Processed a new package!", currentPack);
}
}
} else {
console.error("Error: ", body);
Expand Down

0 comments on commit ffac538

Please sign in to comment.