hamsando / node-red-contrib-stoptimer-varidelay

Apache License 2.0
7 stars 2 forks source link

Resume timer on deply/restart not working in subflow - within a subflow #11

Closed hamsando closed 3 years ago

hamsando commented 3 years ago

In my setup I have subflows that call other subflows that again have timer nodes. With this constellation there is still the problem, that the subflow node, which is placed in another subflow, changes its id during a redeploy. Maybe you can investigate to generate a filename which contains all ids of the subflow chain to solve it. I like this feature very much, so it would be great, if you can look into it again.

Originally posted by @tobi-bo in https://github.com/hamsando/node-red-contrib-stoptimer-varidelay/issues/10#issuecomment-800034044

hamsando commented 3 years ago

This one is challenging - I've done a fair bit of poking around and trialing different approaches and so far haven't found any reasonable method for handling the "subflow-within-a-subflow" scenario.

While I have not given up, I do not anticipate this as being fixed any time soon.

tobi-bo commented 3 years ago

Hi, yeah, I can imagine, that this one is difficult. Maybe you can share your thoughts, so that one can help you with ideas. So far I am not familiar enough with Javascript and especially with the Node-RED program model to experiment with the code myself. Apart from the fact that I don't have a suitable development environment to test it. But I would like to contribute to the solution with a few thoughts.

hamsando commented 3 years ago

The only way I could figure to possibly do it would be to add code into the stoptimer-varidelay node which would use the node id/_alias to query:

http://node-red_ip:port/flows (see: https://nodered.org/docs/api/admin/methods/)

and parse through the JSON to map out the "z" of the subflows (when it comes to subflows within subflows you can't use the "z" the node itself reports as that will be dynamic, however the "z" reported in the API seems to be static. Once the node has a map back up to the tab it is in, that map would become the unique name for the node.

The above is theoretical and is based on a manual review of the contents of the /flows endpoint for a fairly simple set subflows within subflows.

The concern with implementation is that because of the complexities and many moving parts of flows within flows (within flows ...) is that it becomes really easy for the end user to make a change to the flow, not realizing the impact it has to a timer deep down the rabbit hole.

The other concern is that each timer node would have to do this query on each startup, or redeploy - this is probably not ideal.

UPDATE: Upon further investigation this won't work.

tobi-bo commented 3 years ago

Hi, installed a node red DEV environment on my PC and played around with it a bit. I found a variable in _flow object which represents the complete node path and used this to create the file name. It works well in my tests. I created a PR for this, so you can please review it and maybe merge it.

hamsando commented 3 years ago

Pretty slammed at work right now - so I probably won't be able to review until the weekend. Thanks for the help!

hamsando commented 3 years ago

Fixed in 0.5.2

tobi-bo commented 3 years ago

cool, works perfectly :-)