* Atomically claim the queue for sending (rename). Concurrent processes * can't double-send; a crash mid-send leaves a claim file that * `recoverStaleClaims` merges back after an hour.
()
| 507 | * `recoverStaleClaims` merges back after an hour. |
| 508 | */ |
| 509 | private claimQueue(): { claimPath: string; lines: BufferLine[] } | null { |
| 510 | const claimPath = path.join(this.dir, `telemetry-queue.sending.${process.pid}.jsonl`); |
| 511 | try { |
| 512 | fs.renameSync(this.queuePath, claimPath); |
| 513 | } catch { |
| 514 | return null; // no queue, or another process just claimed it |
| 515 | } |
| 516 | let lines: BufferLine[] = []; |
| 517 | try { |
| 518 | lines = parseLines(fs.readFileSync(claimPath, 'utf8')); |
| 519 | } catch { |
| 520 | /* unreadable claim — treat as empty; file removed by caller */ |
| 521 | } |
| 522 | return { claimPath, lines }; |
| 523 | } |
| 524 | |
| 525 | private recoverStaleClaims(): void { |
| 526 | try { |
no test coverage detected