Refactor pulse check logic to run continuously and delay until midnight

This commit is contained in:
MarcUs7i 2025-02-28 21:48:21 +01:00
parent 418166091c
commit fb0db1f959

View file

@ -162,8 +162,7 @@ const checkOnionService = async (host, port) => {
} }
}; };
// Extract pulse check into a separate function while(true) {
const runPulseCheck = async () => {
config.verbose && console.log('🔄 Pulse'); config.verbose && console.log('🔄 Pulse');
let startPulse = Date.now(); let startPulse = Date.now();
let status; let status;
@ -340,24 +339,5 @@ const runPulseCheck = async () => {
console.error(e); console.error(e);
} }
config.verbose && console.log('✅ Done'); config.verbose && console.log('✅ Done');
}; await delay(getMillisUntilMidnight());
}
// Run pulse check immediately on startup
await runPulseCheck();
// Schedule pulse check to run at midnight every day
const scheduleMidnightCheck = async () => {
const millisUntilMidnight = getMillisUntilMidnight();
await delay(millisUntilMidnight);
await runPulseCheck();
setInterval(async () => {
await runPulseCheck();
}, 24 * 60 * 60 * 1000); // 24 hours
};
scheduleMidnightCheck();
// Regular interval checks
setInterval(async () => {
await runPulseCheck();
}, config.interval);