From 038cb730e019ea91ec7491a0cfccdec986a94f85 Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Sun, 13 Sep 2026 23:30:15 -0300 Subject: [PATCH] fix(C155): probe do VOD com uma retentativa para absorver reset transiente do CDN --- scripts/lib/camaraFetch.mjs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/lib/camaraFetch.mjs b/scripts/lib/camaraFetch.mjs index d14c340f..8bc8ce2d 100644 --- a/scripts/lib/camaraFetch.mjs +++ b/scripts/lib/camaraFetch.mjs @@ -118,13 +118,15 @@ export async function resolveVod(eventId, excerpt) { /** * Lightweight reachability probe of one stored VOD link (C155 sample check): * GET with a 1 KiB `Range` so the MP4 body never streams, falling back to HEAD - * when the server refuses the ranged GET (405/501). Never throws — a network - * error becomes an `ok: false` result so one dead link cannot abort the report. + * when the server refuses the ranged GET (405/501). One retry absorbs the + * CDN's transient connection resets; it never throws — a network error becomes + * an `ok: false` result so one dead link cannot abort the report. * * @param {string | null | undefined} url + * @param {{ timeoutMs?: number, attempts?: number }} [options] * @returns {Promise<{ url: string | null, status: number | null, ok: boolean, note: string }>} */ -export async function probeVodLink(url, { timeoutMs = 20_000 } = {}) { +export async function probeVodLink(url, { timeoutMs = 20_000, attempts = 2 } = {}) { if (!url) return { url: null, status: null, ok: false, note: 'sem link' } const request = async (method) => { @@ -142,13 +144,18 @@ export async function probeVodLink(url, { timeoutMs = 20_000 } = {}) { return { url, status: response.status, ok: response.ok, note } } - try { - const first = await request('GET') - if (first.status === 405 || first.status === 501) return await request('HEAD') - return first - } catch (error) { - return { url, status: null, ok: false, note: error?.message ?? String(error) } + let lastError + for (let attempt = 1; attempt <= attempts; attempt += 1) { + try { + const first = await request('GET') + if (first.status === 405 || first.status === 501) return await request('HEAD') + return first + } catch (error) { + lastError = error + if (attempt < attempts) await sleep(1_000) + } } + return { url, status: null, ok: false, note: lastError?.message ?? String(lastError) } } export const DEEPINFRA_COST_PER_MINUTE_USD = 0.00045