From da0ce9fe0d74412546deeb7accdb8ea02113061a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 10 Dec 2015 17:02:09 +0000 Subject: [PATCH] Simplify flow api implementation and add logging messages --- red/runtime/locales/en-US/runtime.json | 3 + red/runtime/nodes/flows/index.js | 181 ++++++++----------------- 2 files changed, 57 insertions(+), 127 deletions(-) diff --git a/red/runtime/locales/en-US/runtime.json b/red/runtime/locales/en-US/runtime.json index 32b440d85..6dbaf2bc4 100644 --- a/red/runtime/locales/en-US/runtime.json +++ b/red/runtime/locales/en-US/runtime.json @@ -89,6 +89,9 @@ "stopped-modified-flows": "Stopped modified flows", "stopped-flows": "Stopped flows", "stopped": "Stopped", + "added-flow": "Adding flow: __label__", + "updated-flow": "Updated flow: __label__", + "removed-flow": "Removed flow: __label__", "missing-types": "Waiting for missing types to be registered:", "missing-type-provided": " - __type__ (provided by npm module __module__)", "missing-type-install-1": "To install any of these missing modules, run:", diff --git a/red/runtime/nodes/flows/index.js b/red/runtime/nodes/flows/index.js index 3bc2d0386..40a3b642f 100644 --- a/red/runtime/nodes/flows/index.js +++ b/red/runtime/nodes/flows/index.js @@ -76,7 +76,7 @@ function load() { }); } -function setConfig(_config,type) { +function setConfig(_config,type,muteLog) { var config = clone(_config); type = type||"full"; @@ -115,8 +115,8 @@ function setConfig(_config,type) { activeFlowConfig = newFlowConfig; return credentials.clean(activeConfig).then(function() { if (started) { - return stop(type,diff).then(function() { - start(type,diff); + return stop(type,diff,muteLog).then(function() { + start(type,diff,muteLog); }).otherwise(function(err) { }) } @@ -199,7 +199,7 @@ function handleStatus(node,statusMessage) { } -function start(type,diff) { +function start(type,diff,muteLog) { //dumpActiveNodes(); type = type||"full"; started = true; @@ -225,10 +225,12 @@ function start(type,diff) { } return when.resolve(); } - if (diff) { - log.info(log._("nodes.flows.starting-modified-"+type)); - } else { - log.info(log._("nodes.flows.starting-flows")); + if (!muteLog) { + if (diff) { + log.info(log._("nodes.flows.starting-modified-"+type)); + } else { + log.info(log._("nodes.flows.starting-flows")); + } } var id; if (!diff) { @@ -270,20 +272,24 @@ function start(type,diff) { } } events.emit("nodes-started"); - if (diff) { - log.info(log._("nodes.flows.started-modified-"+type)); - } else { - log.info(log._("nodes.flows.started-flows")); + if (!muteLog) { + if (diff) { + log.info(log._("nodes.flows.started-modified-"+type)); + } else { + log.info(log._("nodes.flows.started-flows")); + } } return when.resolve(); } -function stop(type,diff) { +function stop(type,diff,muteLog) { type = type||"full"; - if (diff) { - log.info(log._("nodes.flows.stopping-modified-"+type)); - } else { - log.info(log._("nodes.flows.stopping-flows")); + if (!muteLog) { + if (diff) { + log.info(log._("nodes.flows.stopping-modified-"+type)); + } else { + log.info(log._("nodes.flows.stopping-flows")); + } } started = false; var promises = []; @@ -321,10 +327,12 @@ function stop(type,diff) { // can do... so cheat by wiping the map knowing it'll be rebuilt // in start() subflowInstanceNodeMap = {}; - if (diff) { - log.info(log._("nodes.flows.stopped-modified-"+type)); - } else { - log.info(log._("nodes.flows.stopped-flows")); + if (!muteLog) { + if (diff) { + log.info(log._("nodes.flows.stopped-modified-"+type)); + } else { + log.info(log._("nodes.flows.stopped-flows")); + } } resolve(); }); @@ -376,34 +384,18 @@ function updateMissingTypes() { } } -// function dumpActiveNodes() { -// console.log("--------") -// for (var i in activeFlowConfig.allNodes) { -// console.log(i,activeFlowConfig.allNodes[i].type,activeFlowConfig.allNodes[i].z) -// } -// console.log("--------") -// } function addFlow(flow) { - //dumpActiveNodes(); - /* - { - id:'', - label:'', - nodes:[] - } - */ - - // flow.id should not exist - it will be assigned by the runtime - // all flow.{subflows|configs|nodes}.z will be set to flow.id - // check all known types - fail if otherwise? - // - // resolves with generated flow id - - var i,id,node; + var i,node; flow.id = redUtil.generateId(); + var nodes = [{ + type:'tab', + label:flow.label, + id:flow.id + }]; + for (i=0;i 0 && activeFlowConfig.missingTypes.length === 0) { - return start(); - } - //dumpActiveNodes(); - }); - }); - }) - + return setConfig(newConfig,'flows',true).then(function() { + log.info(log._("nodes.flows.removed-flow",{label:(flow.label?flow.label+" ":"")+"["+flow.id+"]"})); + }); } + module.exports = { init: init,