MCPcopy Create free account
hub / github.com/alibaba/open-code-review / readWithPacing

Function readWithPacing

scripts/github-actions/post-review-comments.js:1209–1223  ·  view source on GitHub ↗
(tag, fn, log)

Source from the content-addressed store, hash-verified

1207// secondary limit when issued in a tight loop. Use shorter delays than writes
1208// (READ_SUCCESS_DELAY / READ_LOW_REMAINING_SPACING).
1209async function readWithPacing(tag, fn, log) {
1210 const res = await withRetry(tag, fn, log);
1211 const remaining = logRateLimitQuota(res, tag, log);
1212 const LOW_REMAINING_THRESHOLD = parseNonNegInt(process.env.OCR_LOW_REMAINING_THRESHOLD, 3);
1213 const lowQuota = remaining != null && remaining <= LOW_REMAINING_THRESHOLD;
1214 if (lowQuota) {
1215 const READ_LOW_REMAINING_SPACING = parseNonNegInt(process.env.OCR_READ_LOW_REMAINING_SPACING, 5000);
1216 log(`[rate-limit] quota low after read (${remaining} <= ${LOW_REMAINING_THRESHOLD}); spacing ${READ_LOW_REMAINING_SPACING}ms.`);
1217 await sleep(READ_LOW_REMAINING_SPACING);
1218 } else {
1219 const READ_SUCCESS_DELAY = parseNonNegInt(process.env.OCR_READ_SUCCESS_DELAY, 500);
1220 await sleep(READ_SUCCESS_DELAY);
1221 }
1222 return res;
1223}
1224
1225// Paginated helper that walks all pages of a list endpoint with retry and
1226// pacing. Returns the concatenated array of items.

Callers 2

readAllPagesFunction · 0.85
getPrDiffHunksFunction · 0.85

Calls 5

withRetryFunction · 0.85
logRateLimitQuotaFunction · 0.85
parseNonNegIntFunction · 0.85
sleepFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected