From 6fd17acf7887277543785179a02a8fb5672a27ce Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Wed, 15 Apr 2026 07:49:14 +0530 Subject: [PATCH] =?UTF-8?q?fix(cdr-enrichment):=2035s=20sleep=20between=20?= =?UTF-8?q?date=20fetches=20=E2=80=94=20Ozonetel=20caps=20at=202/min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/ozonetel/cdr-enrichment.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ozonetel/cdr-enrichment.service.ts b/src/ozonetel/cdr-enrichment.service.ts index 2d5ed6c..19cc7be 100644 --- a/src/ozonetel/cdr-enrichment.service.ts +++ b/src/ozonetel/cdr-enrichment.service.ts @@ -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;