* Builds a stable `insertId` for best-effort dedup (~60s window). Prefixed * with `drainId` so (runId, sequence) collisions across drains do not * accidentally dedupe each other's rows. With UUID drain/run IDs the raw * form fits well under 128 chars; if anything pushes it over (e.g. a future *
(metadata: DeliveryMetadata, index: number)
| 139 | * suffix intact so BigQuery does not silently dedupe distinct rows. |
| 140 | */ |
| 141 | function buildInsertId(metadata: DeliveryMetadata, index: number): string { |
| 142 | const raw = `${metadata.drainId}-${metadata.runId}-${metadata.sequence}-${index}` |
| 143 | if (raw.length <= MAX_INSERT_ID_LENGTH) return raw |
| 144 | const prefixHash = createHash('sha1') |
| 145 | .update(`${metadata.drainId}-${metadata.runId}-${metadata.sequence}`) |
| 146 | .digest('hex') |
| 147 | return `${prefixHash}-${index}` |
| 148 | } |
| 149 | |
| 150 | const RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504]) |
| 151 | const MAX_RETRY_ATTEMPTS = 3 |