add logging, use external link

This commit is contained in:
lyc8503 committed 2024-03-18 17:01:58 +08:00
1 parent 904e0bc49b
commit 8102258e3b
2 files changed
+7 -3

No files matched your search

+6 -2
View File
@@ -220,14 +220,18 @@ export default {
state.latency[monitor.id] = latencyLists
}
console.log(`statusChanged: ${statusChanged}, lastUpdate: ${state.lastUpdate}, currentTime: ${currentTimeSecond}`)
// Update state
state.lastUpdate = Math.round(Date.now() / 1000)
// Allow for a cooldown period before writing to KV
if (
statusChanged ||
currentTimeSecond - state.lastUpdate >= workerConfig.kvWriteCooldownMinutes * 60
currentTimeSecond - state.lastUpdate >= workerConfig.kvWriteCooldownMinutes * 60 - 10 // Allow for 10 seconds of clock drift
) {
console.log("Updating state...")
state.lastUpdate = currentTimeSecond
await env.UPTIMEFLARE_STATE.put('state', JSON.stringify(state))
} else {
console.log("Skipping state update due to cooldown period.")
}
},
}