From 9b5cf280921d1cf34b9968d9ec40e1699520c25a Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Tue, 20 Mar 2018 22:19:25 +0100 Subject: [PATCH] Ensure requests get a response --- src/protocol/Network.coffee | 49 ++++++++++++++++++++++++++----------- src/protocol/Runtime.coffee | 1 + 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/protocol/Network.coffee b/src/protocol/Network.coffee index 3e70b19..ea25a7f 100644 --- a/src/protocol/Network.coffee +++ b/src/protocol/Network.coffee @@ -222,12 +222,25 @@ class NetworkProtocol extends EventEmitter return stopNetwork: (graph, payload, context) -> - return unless @networks[payload.graph] + unless @networks[payload.graph] + @send 'error', new Error("Network #{payload.graph} not found"), context + return net = @networks[payload.graph].network - return unless net + unless net + @send 'error', new Error("Network #{payload.graph} not found"), context + return if net.isStarted() @networks[payload.graph].network.stop (err) => - return @send 'error', err, context if err + if err + @send 'error', err, context + return + @send 'stopped', + time: new Date + graph: payload.graph + running: net.isRunning() + started: net.isStarted() + , context + return return # Was already stopped, just send the confirmation @send 'stopped', @@ -238,22 +251,30 @@ class NetworkProtocol extends EventEmitter , context debugNetwork: (graph, payload, context) -> - return unless @networks[payload.graph] + unless @networks[payload.graph] + @send 'error', new Error("Network #{payload.graph} not found"), context + return net = @networks[payload.graph].network - return unless net - if net.setDebug? - net.setDebug payload.enable - else - console.log 'Warning: Network.setDebug not supported. Update to newer NoFlo' + unless net + @send 'error', new Error("Network #{payload.graph} not found"), context + return + net.setDebug payload.enable + @send 'setdebug', + enable: payload.enable + return getStatus: (graph, payload, context) -> - return unless @networks[payload.graph] + unless @networks[payload.graph] + @send 'error', new Error("Network #{payload.graph} not found"), context + return net = @networks[payload.graph].network - return unless net + unless net + @send 'error', new Error("Network #{payload.graph} not found"), context + return @send 'status', - graph: payload.graph - running: net.isRunning() - started: net.isStarted() + graph: payload.graph + running: net.isRunning() + started: net.isStarted() , context module.exports = NetworkProtocol diff --git a/src/protocol/Runtime.coffee b/src/protocol/Runtime.coffee index 2f76480..c230182 100644 --- a/src/protocol/Runtime.coffee +++ b/src/protocol/Runtime.coffee @@ -96,6 +96,7 @@ class RuntimeProtocol extends EventEmitter when 'packet' then @sendPacket payload, (err) => if err @sendError err.message, context + # TODO: Ack packet send return getRuntime: (payload, context) ->