(tag, fn, log)
| 1207 | // secondary limit when issued in a tight loop. Use shorter delays than writes |
| 1208 | // (READ_SUCCESS_DELAY / READ_LOW_REMAINING_SPACING). |
| 1209 | async 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. |
no test coverage detected