I need a little help because I'm not sure how to do that.
In my flow I try to do a test every hour and, if the test conditions are not met, I send a message to a delay node, which sends it 600 seconds later. Again it checks the conditions and chooses whether it can be done or not. Below the delay node I can see that it has a saved message and every 10 minutes it tries. All in order. My problem comes when an hour has passed and from the other branch of the flow it asks to run the test. As the conditions are still not met, the delay node accumulates already two messages. I would like that, if a correct test is executed, that queue of messages is deleted. ChatGPT has suggested resetQueue, clearDelayQueue... but none seem to work, is there any way to manage that queue?
This is the relevant part of the flow:
[
{
"id": "f999d97252cdff61",
"type": "function",
"z": "4bc9c196469b40da",
"name": "function 16",
"func": "var pruebaEnCurso = global.get(\"pruebaEnCurso\");\n\nif (pruebaEnCurso === 1) {\n // No pasar el mensaje si la prueba está en curso\n return null;\n} else {\n return msg;\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2750,
"y": 3520,
"wires": [
[
"a80b8efb8fd23641"
]
]
},
{
"id": "2ac20b42f105efea",
"type": "delay",
"z": "4bc9c196469b40da",
"name": "Retardo prueba",
"pauseType": "delayv",
"timeout": "600",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 2480,
"y": 3520,
"wires": [
[
"f999d97252cdff61"
]
]
},
{
"id": "c60dab23eb6b8b79",
"type": "function",
"z": "4bc9c196469b40da",
"name": "Borrar cola de retardo",
"func": "if (msg.resetQueue) {\n context.set('delayQueue', []);\n node.status({ fill: 'yellow', shape: 'dot', text: 'Cola de mensajes borrada' });\n return null;\n}\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2260,
"y": 3520,
"wires": [
[
"2ac20b42f105efea"
]
]
},
{
"id": "cdaef70eb0cbcb74",
"type": "function",
"z": "4bc9c196469b40da",
"name": "Establecer tiempo repeticiĂłn",
"func": "var valorguardado = global.get(\"valorguardado\");\n\nif (valorguardado === 2) {\n msg.delay = global.get('repeticionPrueba');\n return msg;\n} else {\n return null;\n}\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2000,
"y": 3520,
"wires": [
[
"c60dab23eb6b8b79"
]
]
},
{
"id": "a80b8efb8fd23641",
"type": "function",
"z": "4bc9c196469b40da",
"name": "interrumpeFlujo",
"func": "var permitirFlujo = global.get(\"permitirFlujo\");\nvar AlarmasL1 = global.get(\"AlarmasL1\");\nvar AlarmasL2 = global.get(\"AlarmasL2\");\nvar AlarmasL3 = global.get(\"AlarmasL3\");\nvar Alarmas = AlarmasL1 + AlarmasL2 + AlarmasL3;\nvar Pminima = parseFloat(global.get(\"Pminima\"));\nvar pruebaEnCurso = global.get(\"pruebaEnCurso\");\nvar sumaPotencias = parseFloat(global.get(\"sumaPotencias\"));\n\nif (pruebaEnCurso === 0) {\nif (permitirFlujo === true && Alarmas === 0 && (sumaPotencias >= Pminima)) {\n return [msg, null];\n} else {\n return [null, msg];\n}\n} else {\n return [null, null];\n}",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1540,
"y": 3520,
"wires": [
[
"db98972b6495dd4b"
],
[
"cdaef70eb0cbcb74"
]
]
},
{
"id": "965e7851219bc56d",
"type": "function",
"z": "4bc9c196469b40da",
"name": "Calculo porcentaje ahorro global",
"func": "msg.payload = Number((((global.get(\"n4500sin\") - global.get(\"n4500\")) / global.get(\"n4500\")) * 100).toFixed(2));\nglobal.set(\"ahorroglobal\", msg.payload);\nglobal.set(\"pruebaEnCurso\", 0);\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1570,
"y": 3420,
"wires": [
[
"73282d0ba95dd0f8"
]
]
},
{
"id": "73282d0ba95dd0f8",
"type": "function",
"z": "4bc9c196469b40da",
"name": "0 < Ahorro < 20",
"func": "if ((msg.payload > 0) && (msg.payload <= 20)) {\n var msg1 = { ...msg }; // Copia del mensaje original para enviar por la salida 1\n var msg2 = { resetQueue: true }; // Sólo contiene clearDelayQueue para enviar por la salida 2\n return [msg1, msg2];\n} else {\n return [null, msg]; // Enviar por la salida 2 si el ahorro está fuera del rango\n}",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1820,
"y": 3420,
"wires": [
[
"516ceafb171cf084"
],
[
"cdaef70eb0cbcb74"
]
]
},
{
"id": "516ceafb171cf084",
"type": "function",
"z": "4bc9c196469b40da",
"name": "Establecer ahorro global",
"func": "if (msg.payload <= 0) {\n msg.payload = 0;\n global.set(\"ahorroglobal\", 0.0);\n} else if (msg.payload > 20) {\n msg.payload = 20;\n global.set(\"ahorroglobal\", 20.0);\n}\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2150,
"y": 3420,
"wires": [
[
"c4bca1adc670cbd3",
"0f71729b007040d6"
]
]
}
]