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

Function readWithPacing

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

Source from the content-addressed store, hash-verified

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