1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2025-07-06 03:52:46 +02:00

feat: move gc monitors from cron schedule to deploy postCommands

This commit is contained in:
Adam Janis
2020-11-18 21:01:56 +01:00
parent 126a48b5cb
commit fe1b63424d
7 changed files with 105 additions and 35 deletions

View File

@ -3,7 +3,6 @@ import config from '../../config.yaml'
import {
setKV,
getKVWithMetadata,
gcMonitors,
getKV,
notifySlack,
} from './helpers'
@ -70,8 +69,5 @@ export async function processCronTrigger(event) {
const loc = res.headers.get('cf-ray').split('-')[1]
await setKV('lastUpdate', Date.now(), { loc })
// gc monitor statuses
event.waitUntil(gcMonitors(config))
return new Response('OK')
}

View File

@ -56,26 +56,6 @@ export async function deleteKV(key) {
return KV_STATUS_PAGE.delete(key)
}
export async function gcMonitors(config) {
const checkKvPrefix = 's_'
const monitors = config.monitors.map(key => {
return key.id
})
const kvMonitors = await listKV(checkKvPrefix)
const kvState = kvMonitors.keys.map(key => {
return key.metadata.id
})
const keysForRemoval = kvState.filter(x => !monitors.includes(x))
for (const key of keysForRemoval) {
console.log('gc: deleting ' + checkKvPrefix + key)
await deleteKV(checkKvPrefix + key)
}
}
export async function notifySlack(monitor, newMetadata) {
const payload = {
attachments: [