Is it possible for my custom node to subscribe to the flow restart event? This would be to allow me to run some code when the flows restart.
TIA
Is it possible for my custom node to subscribe to the flow restart event? This would be to allow me to run some code when the flows restart.
TIA
Which flow? All flows on all tabs? just your node? the flow your custom node is on?
When the deploy affects the custom node it will re-initialise it. Put `console.log("xxx") thoughout your custom node .js file - you will see one or more in the console log entries when you re-deploy.
The scenario is this, I make a change in the editor and click the Deploy button. That appears to restart all flows. When a given flow restarts, I need to execute code within that flow.
I added a ridiculous number of console.log() statements, and it appears that it runs the node.on("close", function (done) {
function, but the function stops in the middle (I'm guessing it takes too long and the framework just kills it). I think I can work with "close".
It depends what you are trying to do. Is it the stopping of the flows you care about, or the starting of them?
You cannot do lots of work in the close event - you certainly can't assume the flow you're wired to is all still running as the runtime is busy stopping everything.
Whenever the flows are restarted, your node will be recreated - so its constructor function will get called. If you want it to do something whenever a deploy happens, that is the place to do it.
Note that the Deploy button has a number of options in its drop down selection. If it is set to Modified Nodes, for example, only nodes that have been modified will be restarted, so your node will not see the event (unless it is one of the ones that has been modified of course).
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
is happening? And affecting the node itself, or the "child-nodes" which are depending on it?
(More about it here...)
Isn't there a hook for that? I would assume that would be the right way to trigger handlers for events.
I don't think so. Investigated it for 10 hours. It is too low level and would be called every each time some other type of node changes too.
But I've found this here : RED.events
RED.events.on("deploy", function() {
console.log("deploy happen- ed/ing?")
})
... will test it tomorrow.
is that a frontend thing? IIRC there are hooks and actions in the backend and events in the frontend but I might well be incorrect on that...
... "deploy"
event never getting fired.
(and not some error)
PS: tryied to find in NR's code where:
[info] Stopping modified nodes
based on "flows": {"stopping-modified-nodes": ...
is printed to the consol log, but no files contain it other than the language locales\..\runtime.json
files.
The close
event handler on the node will be passed a boolean flag to say if the node is stopping because it has been removed from the flow config or not.
Otherwise, there is no way for the node to know why its being closed (ie a deploy of some flavour, or a full shutdown of the runtime).
If the registered listener accepts two arguments, the first will be a boolean flag that indicates whether the node is being closed because it has been removed entirely, or that it is just being restarted. It will also be set to true if the node has been disabled.
this.on('close', function(removed, done) {
if (removed) {
// This node has been disabled/deleted
} else {
// This node is being restarted
}
done();
});
That's a bit of shocking. I've thought there is at least ONE flag, that would tell, if NR is shutting down. After all, it is doing it, and showing the process on the console.
From my point of view...
Without these it won't be able to handle
@knolleary Is there any obstacle that would prevent to declare some global variables in NR, like:
RED.starting (bool)
RED.stopping (bool)
RED.on("startstop", callback)
RED.deploying (bool)
RED.on("deploy", callback(partial))
When a node is told to closest should clean up its own subscriptions. If a node has a “master” configuration node that can wait until all the children it knows about have stopped (or told it they have) before calling its own done method.