From 5ff9a64e5e162451ed1dd65c44b4f26532177ab9 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 14 Oct 2021 14:42:34 +0800 Subject: [PATCH] [Push Type] Fix missing duration calculation (#685) --- server/routers/api-router.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/routers/api-router.js b/server/routers/api-router.js index 0da1fd70..927a5464 100644 --- a/server/routers/api-router.js +++ b/server/routers/api-router.js @@ -18,6 +18,7 @@ router.get("/api/entry-page", async (_, response) => { router.get("/api/push/:pushToken", async (request, response) => { try { + let pushToken = request.params.pushToken; let msg = request.query.msg || "OK"; let ping = request.query.ping; @@ -30,12 +31,20 @@ router.get("/api/push/:pushToken", async (request, response) => { throw new Error("Monitor not found or not active."); } + const previousHeartbeatTime = await R.getCell(` + SELECT time FROM heartbeat + WHERE id = (select MAX(id) from heartbeat where monitor_id = ?) + `, [ + monitor.id + ]); + let bean = R.dispense("heartbeat"); bean.monitor_id = monitor.id; bean.time = R.isoDateTime(dayjs.utc()); bean.status = UP; bean.msg = msg; bean.ping = ping; + bean.duration = dayjs(bean.time).diff(dayjs(previousHeartbeatTime), "second"); await R.store(bean);