How to respond to deployments in a plugin

Hi folks,

I am trying to use plugins to create a sidebar, based on this gist example.
It seems that the onadd is only called at the beginning.
But I need to do some re-initialization after every deploy (where I can search for the newly deployed nodes).

Unfortunately my Node-RED development time has dropped below freezing point, so I don't have time to start digging into the core.

Can anybody give me a tip about how to handle deployments in a plugin.

Thanks!!!!
Bart

You have 3 events that you can add listeners to 'nodes:add', 'nodes:change', 'nodes:remove'.

I use them in combination with an API to detect committed changes vs uncommitted. That's because uibuilder needs to track url names regardless of whether deployed or not.

    RED.events.on('nodes:add', function(node) {
        if ( node.type === 'uibuilder') {
            // Keep a list of uib nodes in the editor
            // may be different to the deployed list
            editorInstances[node.id] = node.url
            // -- IF uibuilderInstances <> editorInstances THEN there are undeployed instances. --
        } 
    })
    RED.events.on('nodes:change', function(node) {
        if ( node.type === 'uibuilder') {
            mylog('nodes:change:', node)
            editorInstances[node.id] = node.url
        }
    }) 
    RED.events.on('nodes:remove', function(node) {
        if ( node.type === 'uibuilder') {
            mylog('>> nodes:remove >>', node)
            delete editorInstances[node.id]
        }
    })

The full list of editor events are listed here:

https://nodered.org/docs/api/ui/events/

1 Like

Hi guys,

I think my question was not complete enough. I meant on the server side of the plugin.

My .js file contains this:

RED.plugins.registerPlugin("my-sidebar-plugin", {
   onadd: function() {
      // The server side code of my plugin
   }
})

The onadd is nicely called at the startup, so I can use that to initialize some stuff.
But I was wondering if such a plugin also offered things like ondeploy, onclose, ...

Because I need to execute some code at the server side of my plugin, after a deploy has been executed.

I am aware that my plugin has no data from its own, but I need to collect on the server some information about data of nodes that have been deployed.

Yes,

this.on('close', (removed,done) => {
    // ...
})

from inside the registered callback function.

I don't think you need that since your registered callback will be executed if a node instance is (re)deployed.

So this is how uibuilder is structured:

The on close handler is defined in nodeInstance which also creates the node and registers the on input callback.

Julian,
the onadd callback function of my plugin is only called once at the start, but not at a (re)deploy unfortunately.

Will get back here tomorrow. My Node-RED time is up again for today...

I might be confused but:

  • onadd is only run on FIRST deploy
  • nodeInstance is run when any node instance is deployed or redeployed
  • runtimeSetup is only run once - I think when the Node is added to the palette
  • on close is run whenever a node instance is removed and deploy or when Node-RED closes, it runs for each instance.

What do you actually want to run and when?

Sorry - I think I AM confused because you are deploying a PLUGIN not a node :slight_smile:

Hi Julian,
Nice example in your screenshot!! Very self explaining...

Yes indeed that all works fine for a NODE, but I don't know if that is also possible for a PLUGIN.
I need something similar to your nodeInstance, but for a plugin.
Not sure how I can achieve that.

Yep. I've not done a plugin and I was a bit slow on the uptake :slight_smile:

1 Like

@BartButenaers There are 4 events of interest (I may not get all the names right): flows:stopping, flows:stopped, flows:starting, and flows:started. I settled to using the flows:started one. You get passed the event type, a diff of nodes (to be removed, to be changed, to be started, something like that...), and the full flow config. The config tells you about all nodes coming from the flow editor, i.e., these are not exactly the running nodes (subflows and that type of fun stuff). But you can then also access the actually running nodes using RED.nodes.getnode. Some code and comments from the node-red flexdash plugin may be helpful.

2 Likes

Your repo is becoming the WikiLeaks of Node-RED :wink:
I think that your code snippet will indeed do the job for me.
Thanks for sharing these cool ideas!!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.