From 418166091cd8b798388ac4cd8699aea146eb7f20 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Fri, 28 Feb 2025 21:40:28 +0100 Subject: [PATCH] Refactor pulse check logic and schedule regular checks --- watcher.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/watcher.js b/watcher.js index f1ba126..35b16eb 100644 --- a/watcher.js +++ b/watcher.js @@ -162,7 +162,8 @@ const checkOnionService = async (host, port) => { } }; -while(true) { +// Extract pulse check into a separate function +const runPulseCheck = async () => { config.verbose && console.log('🔄 Pulse'); let startPulse = Date.now(); let status; @@ -339,5 +340,24 @@ while(true) { console.error(e); } config.verbose && console.log('✅ Done'); - await delay(getMillisUntilMidnight()); -} \ No newline at end of file +}; + +// 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); \ No newline at end of file