Rename some config options

Original names are still supported for compatibility.
This commit is contained in:
Zaid Abdulla committed 2017-03-07 11:38:56 -08:00
1 parent 848894d3e3
commit 38e83d8544
3 files changed
+34 -18

No files matched your search

+22 -3
View File
@@ -49,13 +49,13 @@ options = {
DOWNLOAD_TIMEOUT: {type : 'int', default : 3600},
EXT_TIMEOUT: {type: 'int', default: 3000},
PRESETS_CACHE_DURATION : {type : 'int', default : 86400},
MAX_CACHE_TTL : {type : 'int', default : 86400},
DEBUG : {type : 'bool', default : false},
RETRY_DELAY : {type : 'int', default : 300},
SESSION_TIMEOUT : {type : 'int', default : 30},
CONNECTION_REQUEST_TIMEOUT : {type : 'int', default: 2000},
GET_PARAMETER_NAMES_DEPTH_THRESHOLD : {type : 'int', default : 0},
TASK_PARAMETERS_BATCH_SIZE : {type : 'int', default : 32},
GPN_NEXT_LEVEL : {type : 'int', default : 0},
GPV_BATCH_SIZE : {type : 'int', default : 32},
MAX_DEPTH : {type: 'int', default : 16},
COOKIES_PATH : {type : 'string'},
LOG_FORMAT : {type : 'string', default : 'simple'},
@@ -79,6 +79,25 @@ allConfig = {}
setConfig = (name, value, commandLineArgument) ->
return true if allConfig[name]?
# For compatibility with v1.0
if name in ['PRESETS_CACHE_DURATION', 'presets-cache-duration']
setConfig('MAX_CACHE_TTL', value)
if name in ['GET_PARAMETER_NAMES_DEPTH_THRESHOLD', 'get-parameter-names-depth-threshold']
setConfig('GPN_NEXT_LEVEL', value)
if name in ['TASK_PARAMETERS_BATCH_SIZE', 'task-parameters-batch-size']
setConfig('GPV_BATCH_SIZE', value)
if name in ['IGNORE_XML_NAMESPACES', 'ignore-xml-namespaces']
setConfig('XML_IGNORE_NAMESPACE', value)
if name in ['XML_PARSE_IGNORE_ENC', 'xml-parse-ignore-enc']
setConfig('XML_IGNORE_ENC', value)
if name in ['XML_PARSE_RECOVER', 'xml-parse-recover']
setConfig('XML_RECOVER', value)
cast = (val, type) ->
switch type
when 'int'
+6 -6
View File
@@ -466,7 +466,7 @@ getDueTasksAndFaultsAndOperations = (deviceId, timestamp, callback) ->
if tasks? and faults? and operations?
return callback(null, tasks, faults, operations)
CACHE_DURATION = config.get('PRESETS_CACHE_DURATION', deviceId)
MAX_CACHE_TTL = config.get('MAX_CACHE_TTL', deviceId)
if not faults?
getFaults(deviceId, (err, flts) ->
@@ -488,7 +488,7 @@ getDueTasksAndFaultsAndOperations = (deviceId, timestamp, callback) ->
if nextTimestamp?
exp = Math.min(0, Math.trunc((nextTimestamp - Date.now()) / 1000))
else
exp = CACHE_DURATION
exp = MAX_CACHE_TTL
redisClient.setex("#{deviceId}_tasks", exp, JSON.stringify(dueTasks), (err) ->
if err
@@ -529,9 +529,9 @@ getFaults = (deviceId, callback) ->
r.provisions = JSON.parse(r.provisions)
faults[channel] = r
CACHE_DURATION = config.get('PRESETS_CACHE_DURATION', deviceId)
MAX_CACHE_TTL = config.get('MAX_CACHE_TTL', deviceId)
redisClient.setex("#{deviceId}_faults", CACHE_DURATION, JSON.stringify(faults), (err) ->
redisClient.setex("#{deviceId}_faults", MAX_CACHE_TTL, JSON.stringify(faults), (err) ->
callback(err, faults)
)
)
@@ -620,9 +620,9 @@ getOperations = (deviceId, callback) ->
r.retries = JSON.parse(r.retries)
operations[commandKey] = r
CACHE_DURATION = config.get('PRESETS_CACHE_DURATION', deviceId)
MAX_CACHE_TTL = config.get('MAX_CACHE_TTL', deviceId)
redisClient.setex("#{deviceId}_operations", CACHE_DURATION, JSON.stringify(operations), (err) ->
redisClient.setex("#{deviceId}_operations", MAX_CACHE_TTL, JSON.stringify(operations), (err) ->
callback(err, operations)
)
)
+6 -9
View File
@@ -873,8 +873,7 @@ generateGetRpcRequest = (sessionContext) ->
syncState.refreshAttributes.writable.clear()
if syncState.gpn.size
GET_PARAMETER_NAMES_DEPTH_THRESHOLD =
config.get('GET_PARAMETER_NAMES_DEPTH_THRESHOLD', sessionContext.deviceId)
GPN_NEXT_LEVEL = config.get('GPN_NEXT_LEVEL', sessionContext.deviceId)
paths = Array.from(syncState.gpn.keys()).sort((a,b) -> b.length - a.length)
path = paths.pop()
@@ -888,7 +887,7 @@ generateGetRpcRequest = (sessionContext) ->
if v = syncState.gpnPatterns.get(p)
patterns.push([p, (v >> path.length) << path.length])
if path.length >= GET_PARAMETER_NAMES_DEPTH_THRESHOLD
if path.length >= GPN_NEXT_LEVEL
est = estimateGpnCount(patterns)
else
est = 0
@@ -908,13 +907,12 @@ generateGetRpcRequest = (sessionContext) ->
}
if syncState.refreshAttributes.value.size
TASK_PARAMETERS_BATCH_SIZE =
config.get('TASK_PARAMETERS_BATCH_SIZE', sessionContext.deviceId)
GPV_BATCH_SIZE = config.get('GPV_BATCH_SIZE', sessionContext.deviceId)
parameterNames = []
iter = syncState.refreshAttributes.value.values()
while (path = iter.next().value) and
parameterNames.length < TASK_PARAMETERS_BATCH_SIZE
parameterNames.length < GPV_BATCH_SIZE
syncState.refreshAttributes.value.delete(path)
if sessionContext.deviceData.attributes.has(path)
parameterNames.push(path)
@@ -957,12 +955,11 @@ generateSetRpcRequest = (sessionContext) ->
}
# Set values
TASK_PARAMETERS_BATCH_SIZE =
config.get('TASK_PARAMETERS_BATCH_SIZE', sessionContext.deviceId)
GPV_BATCH_SIZE = config.get('GPV_BATCH_SIZE', sessionContext.deviceId)
parameterValues = []
syncState.spv.forEach((v, k) ->
return if parameterValues.length >= TASK_PARAMETERS_BATCH_SIZE
return if parameterValues.length >= GPV_BATCH_SIZE
attrs = sessionContext.deviceData.attributes.get(k)
if (curVal = attrs.value?[1])? and attrs.writable?[1]
val = v.slice()