From 8414f463ad6fb453608246afb82bf56945914e07 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 4 Nov 2013 00:41:14 +0300 Subject: [PATCH] Bug fixes related to calculation of preset hash expiary. --- acs.coffee | 2 +- presets.coffee | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/acs.coffee b/acs.coffee index 62f120b..85ac444 100644 --- a/acs.coffee +++ b/acs.coffee @@ -218,7 +218,7 @@ assertPresets = (currentRequest) -> presets.getDevicePreset(currentRequest.deviceId, allPresets, allObjects, (devicePreset) -> presets.processDevicePreset(currentRequest.deviceId, devicePreset, (taskList, addTags, deleteTags, expiry) -> - db.redisClient.setex("#{currentRequest.deviceId}_presets_hash", Math.ceil(expiry - config.PRESETS_TIME_PADDING), presetsHash, (err, res) -> + db.redisClient.setex("#{currentRequest.deviceId}_presets_hash", Math.floor(Math.max(1, expiry - config.PRESETS_TIME_PADDING)), presetsHash, (err, res) -> throw err if err ) diff --git a/presets.coffee b/presets.coffee index 9870094..747d17d 100644 --- a/presets.coffee +++ b/presets.coffee @@ -148,7 +148,7 @@ exports.getDevicePreset = (deviceId, presets, objects, callback) -> devicePreset.customCommands ?= {} devicePreset.customCommands[filename] ?= {} devicePreset.customCommands[filename].preset ?= {} - devicePreset.customCommands[filename].preset.expiry = parseInt(c.expiry) + devicePreset.customCommands[filename].preset.expiry = parseInt(c.age) devicePreset.customCommands[filename].preset.expiryCommand = c.command continue if not deviceCustomCommands[filename]? or commandName not in deviceCustomCommands[filename] if cmd = common.getParamValueFromPath(device, "_customCommands.#{filename}") @@ -186,8 +186,8 @@ exports.processDevicePreset = (deviceId, devicePreset, callback) -> if presetValue? and currentValue != (presetValue = common.matchType(currentValue, presetValue)) setParameterValues.push([parameterPath, presetValue, parameterDetails.current._type]) else if parameterDetails.preset.expiry? - diff = (now - (parameterDetails.current._timestamp ? 0)) / 1000 - if diff >= expiry + diff = parameterDetails.preset.expiry - (now - (parameterDetails.current._timestamp ? 0)) / 1000 + if diff <= config.PRESETS_TIME_PADDING if parameterDetails.current._value? getParameterValues.push(parameterPath) else @@ -232,8 +232,8 @@ exports.processDevicePreset = (deviceId, devicePreset, callback) -> if commandDetails.preset.value? and currentValue != presetValue taskList.push({device : deviceId, name : 'customCommand', command : commandDetails.preset.valueCommand}) else if commandDetails.preset.expiry? - diff = (now - (commandDetails.current._timestamp ? 0)) / 1000 - if diff <= 0 + diff = commandDetails.preset.expiry - (now - (commandDetails.current._timestamp ? 0)) / 1000 + if diff <= config.PRESETS_TIME_PADDING taskList.push({device : deviceId, name : 'customCommand', command : commandDetails.preset.expiryCommand}) else expiry = Math.min(expiry, diff)