fix(cdr-enrichment): 35s sleep between date fetches — Ozonetel caps at 2/min

The first boot hit 429 because two dates (today + yesterday) were
fetched back-to-back, and the dispose flow's fetchCdrByUCID shares the
same 2-req/min budget. 35s between dates keeps us clear of the cap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 07:49:14 +05:30
parent 846c5f4c9b
commit 6fd17acf78

View File

@@ -53,8 +53,12 @@ export class CdrEnrichmentService implements OnModuleInit, OnModuleDestroy {
let skipped = 0;
// Walk the IST-date window. For each date, pull CDR + patch Calls.
// Sleep 35s between dates — Ozonetel caps CDR endpoints at 2 req/min
// and the dispose flow shares that budget (fetchCdrByUCID per outbound).
const dates = this.recentDatesIst(ENRICHMENT_DATE_WINDOW_DAYS);
for (const date of dates) {
for (let i = 0; i < dates.length; i++) {
const date = dates[i];
if (i > 0) await new Promise((r) => setTimeout(r, 35_000));
const cdrRows = await this.ozonetel.fetchCDR({ date }).catch(() => []);
if (cdrRows.length === 0) continue;