Skip to content

Commit

Permalink
add and check store last measure config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Nov 21, 2024
1 parent 16860ce commit ea16a2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ var config = {
providerUrl: 'http://192.168.56.1:4041',
deviceRegistrationDuration: 'P1M',
defaultType: 'Thing',
expressLimit: '1Mb'
expressLimit: '1Mb',
storeLastMeasure: false
};

module.exports = config;
8 changes: 7 additions & 1 deletion lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ function processEnvironmentVariables() {
'IOTA_FALLBACK_PATH',
'IOTA_LD_SUPPORT_NULL',
'IOTA_LD_SUPPORT_DATASET_ID',
'IOTA_EXPRESS_LIMIT'
'IOTA_EXPRESS_LIMIT',
'IOTA_STORE_LAST_MEASURE'
];
const iotamVariables = [
'IOTA_IOTAM_URL',
Expand Down Expand Up @@ -474,6 +475,11 @@ function processEnvironmentVariables() {
} else {
config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
}
if (process.env.IOTA_STORE_LAST_MEASURE) {
config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
} else {
config.storeLastMeasure = config.storeLastMeasure === true;
}
}

function setConfig(newConfig) {
Expand Down
13 changes: 9 additions & 4 deletions lib/services/ngsi/ngsiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ function init() {
* @param {String} token User token to identify against the PEP Proxies (optional).
*/
function sendUpdateValue(entityName, attributes, typeInformation, token, callback) {
deviceService.storeLastMeasure(attributes, typeInformation, function () {
const newCallback = statsRegistry.withStats('updateEntityRequestsOk', 'updateEntityRequestsError', callback);
return entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback);
});
// check config about store last measure
const newCallback = statsRegistry.withStats('updateEntityRequestsOk', 'updateEntityRequestsError', callback);
if (config.getConfig().storeLastMeasure) {
deviceService.storeLastMeasure(attributes, typeInformation, function () {
return entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback);
});
} else {
entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback);
}
}

/**
Expand Down

0 comments on commit ea16a2c

Please sign in to comment.