commit
aa61f3c04b
|
|
@ -1,13 +1,9 @@
|
|||
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'));
|
||||
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 +12,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 +28,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) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
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'));
|
||||
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 +13,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 +46,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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue