Messages sent via "On Start" only reliable on partial deploy but not during " nodered.service" start. Possible?

node.done is not needed (and it doesnt do anything without (brackets) anyhow)
return is unnecessary if it is the last statement

So I did a test using:

let m = {};
m.payload = "Test Payload";
node.send(m);
node.error('deliberate node.error');

And sure enough i DO get a message in the console log.

image

However the results are mixed, as I expected.

  • FULL Deploy
    • The debug node does NOT receive a message
  • Modify func node then do a NODE ONLY deploy - the msg is sent.
  • recreate the function AFTER all other connected nodes, deploy (Full or Node only) and it DOES send

Proving that the on start occurs in order of node creation (the order the node is stored in the flow)

This, is not a reliable way to use "On Start" IMO. As i said before, to ensure all nodes are initialised and running, you should use an inject (as the inject wont fire untill the "Flows Started" message (i.e. all nodes are initialised)

Demo:

Demo flow (note how the function "I was added first" is at the top and the "I was added 2nd last" is 2nd from the bottom!

[
    {
        "id": "99ad09d05093ee4a",
        "type": "function",
        "z": "3642c7ee286f9c17",
        "name": "I was added first",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "let m = {};\nm.payload = \"Test Payload 2\";\nnode.send(m);\nnode.error('deliberate node.error 2');\n",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 480,
        "wires": [
            [
                "44a542c2d5181115",
                "0484dedcdd96f7e7"
            ]
        ]
    },
    {
        "id": "f22eda38365a0e9b",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 630,
        "y": 260,
        "wires": []
    },
    {
        "id": "6e2f83184fe48a05",
        "type": "delay",
        "z": "3642c7ee286f9c17",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 480,
        "y": 380,
        "wires": [
            [
                "6a9a28c3aa062dc8"
            ]
        ]
    },
    {
        "id": "6a9a28c3aa062dc8",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will work after delay",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 670,
        "y": 380,
        "wires": []
    },
    {
        "id": "44a542c2d5181115",
        "type": "delay",
        "z": "3642c7ee286f9c17",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 470,
        "y": 540,
        "wires": [
            [
                "f53dbbe2cc034447"
            ]
        ]
    },
    {
        "id": "0484dedcdd96f7e7",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will not work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 480,
        "wires": []
    },
    {
        "id": "f53dbbe2cc034447",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will not work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 540,
        "wires": []
    },
    {
        "id": "c2c7afc08e883d45",
        "type": "function",
        "z": "3642c7ee286f9c17",
        "name": "I was added 2nd last",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "let m = {};\nm.payload = \"Test Payload\";\nnode.send(m);\nnode.error('deliberate node.error');\n",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 320,
        "wires": [
            [
                "f22eda38365a0e9b",
                "6e2f83184fe48a05",
                "1dd9f3f48b9f1d7d"
            ]
        ]
    },
    {
        "id": "1dd9f3f48b9f1d7d",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will NOT work (last node in flow)",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 700,
        "y": 320,
        "wires": []
    }
]
1 Like