1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2025-07-04 11:02:48 +02:00

feat(cron): detect and save location of last check

This commit is contained in:
Adam Janis
2020-11-15 15:40:57 +01:00
parent bc0d52e89e
commit c33beabef6
4 changed files with 13 additions and 10 deletions

View File

@ -61,11 +61,16 @@ export async function processCronTrigger(event) {
await setKV(kvFailedDayStatusKey, null)
}
}
// save last check timestamp
await setKV('lastUpdate', Date.now())
}
await gcMonitors(config)
// save last check timestamp including PoP location
const res = await fetch("https://www.cloudflare.com/cdn-cgi/trace")
const resText = await res.text()
const loc = /loc=([\w]{2})/.exec(resText)[1]
await setKV('lastUpdate', Date.now(), {loc})
// gc monitor statuses
event.waitUntil(gcMonitors(config))
return new Response('OK')
}

View File

@ -11,7 +11,7 @@ export async function getMonitorsHistory() {
}
export async function getLastUpdate() {
return await getKV('lastUpdate')
return await getKVWithMetadata('lastUpdate')
}
export async function listKV(prefix = '', cacheTtl = false) {