mirror of
https://github.com/Kizuren/statusPage.git
synced 2025-12-21 21:16:09 +01:00
Refactor pulse check logic and schedule regular checks
This commit is contained in:
parent
8263dd5f56
commit
418166091c
1 changed files with 23 additions and 3 deletions
26
watcher.js
26
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());
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue