From 49108f54427ca5ef801f35c43ef13bdeff18e9eb Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Wed, 7 Sep 2022 11:25:03 +0300 Subject: [PATCH] feat(metrics): added metrics --- metrics/metrics.js | 15 +++++++++++++++ orders/index.js | 1 + 2 files changed, 16 insertions(+) diff --git a/metrics/metrics.js b/metrics/metrics.js index 03ead12..c614a41 100644 --- a/metrics/metrics.js +++ b/metrics/metrics.js @@ -17,6 +17,21 @@ mongoose.connect(`mongodb://${process.env.MONGO_HOST}/mern`, { useCreateIndex: true, }); +app.put('/updateMetrics', async (req, res) => { + try { + const metrics = await utils.retrieveMetrics(); + if (new Date().getDay() == 7) { + metrics.saturdaysCounter++; + } else { + metrics.totalCounter++; + } + await utils.updateMetrics(metrics); + res.sendStatus(200); + } catch(ex) { + res.status(401).send({ message: 'Failed updating metrics' + ex}); + } +}); + app.get('/metrics', async (req, res) => { const metrics = await utils.getMetrics(); res.send({ diff --git a/orders/index.js b/orders/index.js index c7a09f4..65f1f69 100644 --- a/orders/index.js +++ b/orders/index.js @@ -52,6 +52,7 @@ fastify.post('/orders', async function (request, reply) { order.state = 'landed' ordersCollection.insertOne(order); reply.send(order.state).code(200); + await axios.put('http://metrics:3000/updateMetrics') }) fastify.get('/orders', async function (request, reply) {