Skip to content

Commit 6689cf3

Browse files
committed
feat: track primary and secondary rate limit hits for improved monitoring
1 parent 84e340c commit 6689cf3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

scripts/copy-discussions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const TARGET_API_URL = process.env.TARGET_API_URL || 'https://api.github.com';
139139
// by intercepting HTTP 403 responses and retry-after headers
140140
const throttleOptions = {
141141
onRateLimit: (retryAfter, options, octokit) => {
142+
primaryRateLimitHits++;
142143
warn(`Primary rate limit exhausted for request ${options.method} ${options.url}`);
143144
if (options.request.retryCount <= 2) {
144145
warn(`Retrying after ${retryAfter} seconds (retry ${options.request.retryCount + 1}/3)`);
@@ -148,6 +149,7 @@ const throttleOptions = {
148149
return false;
149150
},
150151
onSecondaryRateLimit: (retryAfter, options, octokit) => {
152+
secondaryRateLimitHits++;
151153
warn(`Secondary rate limit detected for request ${options.method} ${options.url}`);
152154
if (options.request.retryCount <= 2) {
153155
warn(`Retrying after ${retryAfter} seconds (retry ${options.request.retryCount + 1}/3)`);
@@ -178,6 +180,8 @@ let createdDiscussions = 0;
178180
let skippedDiscussions = 0;
179181
let totalComments = 0;
180182
let copiedComments = 0;
183+
let primaryRateLimitHits = 0;
184+
let secondaryRateLimitHits = 0;
181185

182186
// Helper functions
183187
function log(message) {
@@ -1245,6 +1249,8 @@ async function main() {
12451249
log(`Discussions skipped: ${skippedDiscussions}`);
12461250
log(`Total comments found: ${totalComments}`);
12471251
log(`Comments copied: ${copiedComments}`);
1252+
log(`Primary rate limits hit: ${primaryRateLimitHits}`);
1253+
log(`Secondary rate limits hit: ${secondaryRateLimitHits}`);
12481254

12491255
if (missingCategories.length > 0) {
12501256
warn("\nThe following categories were missing and need to be created manually:");

0 commit comments

Comments
 (0)