const fs = require('fs'); const config = require('../src/config'); try { const raw = fs.readFileSync(config.heartbeatFile, 'utf8'); const heartbeat = JSON.parse(raw); const ageMs = Date.now() - new Date(heartbeat.timestamp).getTime(); const maxAgeMs = Math.max(config.pollIntervalMs * 3, 120000); if (!heartbeat.timestamp || Number.isNaN(ageMs) || ageMs > maxAgeMs) { console.error('Heartbeat is stale'); process.exit(1); } if (heartbeat.status === 'fatal') { console.error('Parser is in fatal state'); process.exit(1); } process.exit(0); } catch (error) { console.error(error.message); process.exit(1); }