init
This commit is contained in:
25
parser/scripts/healthcheck.js
Normal file
25
parser/scripts/healthcheck.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user