diff --git a/translation-app-assessment/backend/cleanup/index.js b/translation-app-assessment/backend/cleanup/index.js index ef3a301..6b49b26 100644 --- a/translation-app-assessment/backend/cleanup/index.js +++ b/translation-app-assessment/backend/cleanup/index.js @@ -18,9 +18,6 @@ app.use(cookieParser()) app.disable('x-powered-by') require("dotenv"); const cors = require('cors'); -firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.applicationDefault() -}); const corsOptions = { origin: process.env.FRONTEND_URL, @@ -32,7 +29,9 @@ const corsOptions = { app.use(cors(corsOptions)); // Init project and services const projectId = process.env.GCP_PROJECT -firebaseAdmin.initializeApp() +firebaseAdmin.initializeApp({ + credential: firebaseAdmin.credential.applicationDefault() +}); const firestore = firebaseAdmin.firestore() // Function to write monitoring "heartbeat" that cleanup has run const writeMonitoring = async () => { @@ -81,23 +80,23 @@ app.get('/', async (req, res) => { app.post('/', async (req, res, next) => { try { - await kpi() - // Delete chat that have been expired for an hour or longer - const deletionPromises = [] - const collection = firestore.collection('chats') - const deletionTimeThreshold = parseInt(Moment().subtract(1, 'hour').format('x')) - const querySnapshot = await collection.where('expiryDate', '<', deletionTimeThreshold).get() - for (const docSnapshot of querySnapshot.docs) { - deletionPromises.push(collection.doc(docSnapshot.id).delete()) - } - await Promise.all(deletionPromises) - if(process.env.ID_BOT !== undefined) await cleanRatesFromBot(); - await writeMonitoring() - console.log(`deleted chats, size:${querySnapshot.size}`) - - await createLanguagesFromRates(); + // await kpi() + // // Delete chat that have been expired for an hour or longer + // const deletionPromises = [] + // const collection = firestore.collection('chats') + // const deletionTimeThreshold = parseInt(Moment().subtract(1, 'hour').format('x')) + // const querySnapshot = await collection.where('expiryDate', '<', deletionTimeThreshold).get() + // for (const docSnapshot of querySnapshot.docs) { + // deletionPromises.push(collection.doc(docSnapshot.id).delete()) + // } + // await Promise.all(deletionPromises) + // if(process.env.ID_BOT !== undefined) await cleanRatesFromBot(); + // await writeMonitoring() + // console.log(`deleted chats, size:${querySnapshot.size}`) + // + // await createLanguagesFromRates(); await deleteInactiveUsers(); - res.status(204).send() + // res.status(204).send() } catch(e) { next(e) }