From 309612cc137fba10ea80bcff4be438bcfe3eac0e Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Wed, 16 Jun 2021 05:03:26 +1000 Subject: [PATCH 1/2] Update logs to use template strings --- crabfit-backend/routes/taskCleanup.js | 8 ++++---- crabfit-backend/routes/taskLegacyCleanup.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crabfit-backend/routes/taskCleanup.js b/crabfit-backend/routes/taskCleanup.js index abf41c9..2feb364 100644 --- a/crabfit-backend/routes/taskCleanup.js +++ b/crabfit-backend/routes/taskCleanup.js @@ -7,7 +7,7 @@ module.exports = async (req, res) => { const threeMonthsAgo = dayjs().subtract(3, 'month').unix(); - console.log('Running cleanup task at', dayjs().format('h:mma D MMM YYYY')); + console.log(`Running cleanup task at ${dayjs().format('h:mma D MMM YYYY')}`); try { // Fetch events that haven't been visited in over 3 months @@ -16,7 +16,7 @@ module.exports = async (req, res) => { if (oldEvents && oldEvents.length > 0) { let oldEventIds = oldEvents.map(e => e[req.datastore.KEY].name); - console.log('Found', oldEventIds.length, 'events to remove'); + console.log(`Found ${oldEventIds.length} events to remove`); // Fetch availabilities linked to the events discovered let peopleDiscovered = 0; @@ -32,11 +32,11 @@ module.exports = async (req, res) => { await req.datastore.delete(oldEvents.map(event => event[req.datastore.KEY])); - console.log('Cleanup successful:', oldEventIds.length, 'events and', peopleDiscovered, 'people removed'); + console.log(`Cleanup successful: ${oldEventIds.length} events and ${peopleDiscovered} people removed`); res.sendStatus(200); } else { - console.log('Found', 0, 'events to remove, ending cleanup'); + console.log(`Found 0 events to remove, ending cleanup`); res.sendStatus(404); } } catch (e) { diff --git a/crabfit-backend/routes/taskLegacyCleanup.js b/crabfit-backend/routes/taskLegacyCleanup.js index 4ca1d5b..5253413 100644 --- a/crabfit-backend/routes/taskLegacyCleanup.js +++ b/crabfit-backend/routes/taskLegacyCleanup.js @@ -7,7 +7,7 @@ module.exports = async (req, res) => { const threeMonthsAgo = dayjs().subtract(3, 'month').unix(); - console.log('Running LEGACY cleanup task at', dayjs().format('h:mma D MMM YYYY')); + console.log(`Running LEGACY cleanup task at ${dayjs().format('h:mma D MMM YYYY')}`); try { // Fetch events that haven't been visited in over 3 months @@ -17,7 +17,7 @@ module.exports = async (req, res) => { oldEvents = oldEvents.filter(event => !event.hasOwnProperty('visited')); if (oldEvents && oldEvents.length > 0) { - console.log('Found', oldEvents.length, 'events that were missing a visited date'); + console.log(`Found ${oldEvents.length} events that were missing a visited date`); // Filter events that are older than 3 months and missing a visited date oldEvents = oldEvents.filter(event => event.created < threeMonthsAgo); @@ -50,11 +50,11 @@ module.exports = async (req, res) => { } })); - console.log('Legacy cleanup successful:', eventsRemoved, 'events and', peopleRemoved, 'people removed'); + console.log(`Legacy cleanup successful: ${eventsRemoved} events and ${peopleRemoved} people removed`); res.sendStatus(200); } else { - console.log('Found', 0, 'events that are older than 3 months and missing a visited date, ending LEGACY cleanup'); + console.log('Found 0 events that are older than 3 months and missing a visited date, ending LEGACY cleanup'); res.sendStatus(404); } } else { From 4ede03ba76a0ac3a1b76d3825f0eb5a52f27d0e4 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Wed, 16 Jun 2021 05:10:40 +1000 Subject: [PATCH 2/2] Remove cron check --- crabfit-backend/routes/taskCleanup.js | 4 ---- crabfit-backend/routes/taskLegacyCleanup.js | 4 ---- 2 files changed, 8 deletions(-) diff --git a/crabfit-backend/routes/taskCleanup.js b/crabfit-backend/routes/taskCleanup.js index 2feb364..28182e5 100644 --- a/crabfit-backend/routes/taskCleanup.js +++ b/crabfit-backend/routes/taskCleanup.js @@ -1,10 +1,6 @@ const dayjs = require('dayjs'); module.exports = async (req, res) => { - if (req.header('X-Appengine-Cron') === undefined) { - return res.status(400).send('This task can only be run from a cron job'); - } - const threeMonthsAgo = dayjs().subtract(3, 'month').unix(); console.log(`Running cleanup task at ${dayjs().format('h:mma D MMM YYYY')}`); diff --git a/crabfit-backend/routes/taskLegacyCleanup.js b/crabfit-backend/routes/taskLegacyCleanup.js index 5253413..cbb3e6e 100644 --- a/crabfit-backend/routes/taskLegacyCleanup.js +++ b/crabfit-backend/routes/taskLegacyCleanup.js @@ -1,10 +1,6 @@ const dayjs = require('dayjs'); module.exports = async (req, res) => { - if (req.header('X-Appengine-Cron') === undefined) { - return res.status(400).send('This task can only be run from a cron job'); - } - const threeMonthsAgo = dayjs().subtract(3, 'month').unix(); console.log(`Running LEGACY cleanup task at ${dayjs().format('h:mma D MMM YYYY')}`);