Re-deploy a node (or entire flow) on event in node

Sorry for already starting the next topic but this is quite a problem for my workflow so I was hoping there was a way to handle the following issue:

I have a node that when it hits an error can only recover by being deployed again or by restarting the server. So I was wondering if there was a way to redeploy the workflow or the node from the node itself ( like clicking the deploy button, just triggered from the node's on error handler).

I could'nt find a way so far but I've always gotten great help by the people in here so I'm looking forward to any ideas!

Is that your own custom node or someone elses?

I ask because that is, in general, a very poor practice - it may not even be possible, certainly not in every case, depends on how it is being run and what user id is running it.

However, it should fairly easily be fixable in the node and that would be a much better question if it is your own node. If not, then I would strongly recommend raising an issue with the node's owner.

1 Like

Although as Julian I am not sure if it is a good idea, you could use the admin http api https://nodered.org/docs/api/admin/methods/post/flows/ to reload the flows. There is also the method RED.nodes.setFlows, but looking quickly at the code I am not completely sure how to use it and I would also highly recommend to solve your problem differently

1 Like

Indeed - what is this node ? What is the error ?

1 Like

Well first of all TotallyInformation , cinhcet and dceejay thanks for replying and for all the good advice!!!
It's my own node.
Yeah I know it's probably bad practice and a huge overkill but its a case that should almost never occurr ( just as safety net when it actually occurrs to somehow recover the flow from being disturbed by this node, without me having to redeploy the flow manually). The node communicates with a child process instance and IF for some unforeseeable reason that process gets killed I can only get the communication established again by restarting the node ( restarting the child process was obviously my first idea but even though I can get it to restart, theres no way for the node to communicate with the restarted process). So its not the node per se that gets an error - in fact the node just stops sending messages and the flow keeps on going, just without the node's messages.
Maybe cinhcet's idea with RED.nodes.setFlows would be a good idea for me to try to handle this rare case. I'm recently trying to improve error handling on all my nodes and while a lot of if and try catch help me so far to make them quite robust I want to make them handle as much corner cases as possible.
Thanks again for the input! It's highly appreciated

If the child process is killed then you will get an event you can use to restart the process. You may need to clean up your side of the connection before restarting it, but you will be able to reattach the io to it.
This is what the node-red-node-daemon does for instance

2 Likes

That was also my first instinct but I failed in executing it. But maybe I can find the solution by checking the node-red-node-daemon node! Thanks a lot for sharing! I'll dive into that node right away!

I also need to redeploy unless someone can guide me otherwise.
On occasion, and I'm still chasing it, my sqlite database gets 'malformed'.
I have a script to execute to rebuild the database which works fine and it stops node-red and restarts it once it has finished. Node-red doesn't seem to reconnect to the database without a redeploy.
Am I just digging myself a hole here?
My only pointer to the corruption is also using SQLiteStudio to query the database and especially if I make database changes from SQLiteStudio.