Skip to content

Commit

Permalink
Fix: Mietering Service does async clearing commit to ensure quick ret…
Browse files Browse the repository at this point in the history
…urn on meter reading updates
  • Loading branch information
zoernert committed Apr 26, 2024
1 parent a0f163c commit 0e4085a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion framework/services/httppull.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module.exports = {
method: "GET",
path: "/updateReading"
},
timeout:60000,
async handler(ctx) {
const results = await ctx.call("httppull_model.find",{
query: {
Expand All @@ -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 {};
}
}
Expand Down
20 changes: 11 additions & 9 deletions framework/services/metering.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0e4085a

Please sign in to comment.