From e305cede8fd729962bef548ddc805d0ba4e62e18 Mon Sep 17 00:00:00 2001 From: Adam Janis Date: Sat, 14 Nov 2020 02:37:42 +0100 Subject: [PATCH] fix(gc): wait for gc to complete before exiting cron trigger --- pages/index.js | 2 -- src/functions/cronTrigger.js | 1 - src/functions/helpers.js | 6 +++--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pages/index.js b/pages/index.js index 7fe237e..4ef2b6b 100644 --- a/pages/index.js +++ b/pages/index.js @@ -24,8 +24,6 @@ export async function getEdgeProps() { if (x.metadata.operational === false) monitorsOperational = false }) - console.log(JSON.stringify(kvMonitorsMap)) - // transform KV list to array of failed days const kvMonitorsFailedDaysArray = kvMonitorsFailedDays.map(x => { return x.name diff --git a/src/functions/cronTrigger.js b/src/functions/cronTrigger.js index 43351f4..613fd39 100644 --- a/src/functions/cronTrigger.js +++ b/src/functions/cronTrigger.js @@ -53,7 +53,6 @@ export async function processCronTrigger(event) { if (!newMetadata.operational) { // try to get failed daily status first as KV read is cheaper than write const kvFailedDayStatusKey = 'h_' + monitor.id + '_' + getDate() - console.log(kvFailedDayStatusKey) const kvFailedDayStatus = await getKV(kvFailedDayStatusKey) // write if not found diff --git a/src/functions/helpers.js b/src/functions/helpers.js index fd95312..51e8ffd 100644 --- a/src/functions/helpers.js +++ b/src/functions/helpers.js @@ -69,10 +69,10 @@ export async function gcMonitors(config) { const keysForRemoval = kvState.filter(x => !monitors.includes(x)) - keysForRemoval.forEach(key => { + for (const key of keysForRemoval) { console.log('gc: deleting ' + checkKvPrefix + key) - deleteKV(checkKvPrefix + key) - }) + await deleteKV(checkKvPrefix + key) + } } export async function notifySlack(monitor, newMetadata) {