fix(noter): use the fs import instead of require in the heartbeat helpers (#3)

This module is ESM, so `require` is not defined at runtime. `node --check`
only parses, so it passed while both helpers would have thrown: the write
was swallowed by its catch, and the read fell through to `Infinity`, which
the watchdog reads as a permanently stale heartbeat — it would have exited
the process a minute after every scan and left the bot restarting in a loop.

`fs` is already imported at the top of the file; use it.
This commit is contained in:
2026-08-05 14:16:26 -07:00
committed by GitHub
parent 676f2f7474
commit 164a9b4920
+2 -2
View File
@@ -52,7 +52,7 @@ const STALE_AFTER = SCAN_INTERVAL * 3;
function touchHeartbeat() {
try {
require('fs').writeFileSync(HEARTBEAT_FILE, String(Date.now()));
fs.writeFileSync(HEARTBEAT_FILE, String(Date.now()));
} catch (err) {
log('WARN', 'Could not write heartbeat', { error: err.message });
}
@@ -62,7 +62,7 @@ function touchHeartbeat() {
/// yet — an unwritable or missing heartbeat counts as stale rather than healthy.
function heartbeatAge() {
try {
const t = Number(require('fs').readFileSync(HEARTBEAT_FILE, 'utf8'));
const t = Number(fs.readFileSync(HEARTBEAT_FILE, 'utf8'));
return Number.isFinite(t) ? Date.now() - t : Infinity;
} catch {
return Infinity;