added environment variables to control updates of flows

This commit is contained in:
Peter Svensson
2019-06-23 20:59:10 +02:00
parent 0af1a1b15a
commit 8b0ee83c8c
4 changed files with 22 additions and 5 deletions

View File

@ -10,10 +10,20 @@ module.exports = function(RED) {
const cb = (res)=>{
//console.log('firebase get result '+res)
//console.dir(res)
let val = res.val()
runtime.flows.updateFlow({id: val.id, flow: val})
//console.log('val='+val)
node.send({payload:val})
if(config.env_var && process.env[config.env_var]){
let val = res.val()
runtime.flows.getFlow({id: val.id}).then((flow)=>{
console.log('rtdb-to-flow old flow updated_at = '+flow.updated_at+' new flow updated_at = '+val.updated_at)
if(!flow.updated_at || val.updated_at > flow.updated_at){
console.log('updating flow...')
runtime.flows.updateFlow({id: val.id, flow: val})
}
//console.log('val='+val)
node.send({payload:val})
})
} else {
console.log('skipping flow update because environment variable '+config.env_var+' was either not defined or not set to true')
}
}
let setUpListener = (path)=>{