From 0e4085a2a06d2283882d389389124ee1ce4783de Mon Sep 17 00:00:00 2001 From: Thorsten Zoerner Date: Fri, 26 Apr 2024 12:04:34 +0200 Subject: [PATCH] Fix: Mietering Service does async clearing commit to ensure quick return on meter reading updates --- framework/services/httppull.service.js | 3 ++- framework/services/metering.service.js | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/framework/services/httppull.service.js b/framework/services/httppull.service.js index aca426c..940babb 100644 --- a/framework/services/httppull.service.js +++ b/framework/services/httppull.service.js @@ -137,6 +137,7 @@ module.exports = { method: "GET", path: "/updateReading" }, + timeout:60000, async handler(ctx) { const results = await ctx.call("httppull_model.find",{ query: { @@ -148,7 +149,7 @@ module.exports = { json.meterId = results[0].meterId; json.reading *= 1; json.timestamp *= 1000; //TODO: Fix should be done in Template not in code - return await ctx.call("metering.updateReading",json,{timeout:60000}); + return await ctx.call("metering.updateReading",json,{timeout:600000}); } else return {}; } } diff --git a/framework/services/metering.service.js b/framework/services/metering.service.js index ee4b8c7..280bf53 100644 --- a/framework/services/metering.service.js +++ b/framework/services/metering.service.js @@ -362,16 +362,18 @@ module.exports = { transientClearing[key] = value; } } - - const clearing = await ctx.call("clearing.commit",transientClearing); - if(typeof transientReading.id == 'undefined') { - transientReading.id = transientReading._id; - } - if(typeof transientReading._id !== 'undefined') { - transientReading.clearingJWT = clearing.jwt; - delete transientReading._id; - await ctx.call("readings_model.update",{id:transientReading.id,clearingJWT:transientReading.clearingJWT}); // ensures clearing to be part of. + const clearingCommit = async function() { + const clearing = await ctx.call("clearing.commit",transientClearing); + if(typeof transientReading.id == 'undefined') { + transientReading.id = transientReading._id; + } + if(typeof transientReading._id !== 'undefined') { + transientReading.clearingJWT = clearing.jwt; + delete transientReading._id; + await ctx.call("readings_model.update",{id:transientReading.id,clearingJWT:transientReading.clearingJWT}); // ensures clearing to be part of. + } } + clearingCommit(); } delete transientReading._id; // For operational safety we do not provide our db IDs to the client. delete transientReading.id;