Pause cronplus node until restarted (Edited title)

Hi,

@knolleary, @Steve-Mcl

I am not sure if I am using the node correctly, but I seem to be having some problems with this small flow using msg.topic and msg.payload to control the node. Any comments, suggestions greatly accepted!!

Basically I need runs a cron job until a certain condition is met, at which point the cron job is paused. Restart of the paused cron job is at the same time each day. (Seeing if InfluxDB has 'future' data in it, if not, go and fetch until it does!)

My Dummy flow should simulate this...

cronplus set to check for data every 20 seconds
if data (Random node), pause cronplus (and sendEmail - set variable)
if no data, run again in 20 seconds

Restart cronplus from inject node when you want it to run again (same time each day)

However, I seem to be getting data delayed/flooding. I am not sure if this is due to the flow, or the Debug window in Node Red, or something else. The debug messages pause for a while (not every time) and then I get a flood, but the flow should have paused after the first pair of messages in the flood! The delay was added in case of some kind of race condition.

I am aware that I am using the Node-RED 1.1.0-beta.3, hence me posting here now rather than fault find for a few days.

30 Jun 16:00:01 - [info] Node-RED version: v1.1.0-beta.3
30 Jun 16:00:01 - [info] Node.js version: v12.18.1
30 Jun 16:00:01 - [info] Linux 5.3.0-61-generic x64 LE
30 Jun 16:00:01 - [info] Loading palette nodes
30 Jun 16:00:01 - [info] Dashboard version 2.22.1 started at /ui
30 Jun 16:00:01 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
30 Jun 16:00:01 - [info] Settings file : .node-red/settings.js
30 Jun 16:00:01 - [info] Context store : 'default' [module=memory]
30 Jun 16:00:01 - [info] User directory : .node-red
30 Jun 16:00:01 - [warn] Projects disabled : editorTheme.projects.enabled=false
30 Jun 16:00:01 - [info] Flows file : .node-red/flows_XXXX.json
30 Jun 16:00:01 - [info] Server now running at http://127.0.0.1:1880/

[{"id":"91dc1292.bb15b8","type":"function","z":"42c2a631.eb624","name":"Slot got value?","func":"var cost = msg.payload;\nif (cost !== 0) {\n    msg.sendEmail = 1;\n    msg.topic = \"pause\"\n    msg.payload = \"refetch\"\n}\nelse {\n    msg.sendEmail = 0\n    msg.topic = \"start\"\n    msg.payload = \"refetch\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":400,"wires":[["90939623.74a8c8","ebccfa55.f2fed","becebb3b.a72778"]]},{"id":"6a7768be.e5648","type":"cronplus","z":"42c2a631.eb624","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":310,"y":400,"wires":[["2e0e0a52.804b16"]]},{"id":"90939623.74a8c8","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"sendEmail","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":400,"wires":[]},{"id":"2e0e0a52.804b16","type":"random","z":"42c2a631.eb624","name":"","low":"0","high":"1","inte":"true","property":"payload","x":480,"y":400,"wires":[["91dc1292.bb15b8"]]},{"id":"61ed2543.31c014","type":"inject","z":"42c2a631.eb624","name":"","props":[{"p":"payload"},{"p":"topic","v":"start","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"refetch","payloadType":"msg","x":110,"y":280,"wires":[["6a7768be.e5648"]]},{"id":"ebccfa55.f2fed","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":360,"wires":[]},{"id":"becebb3b.a72778","type":"delay","z":"42c2a631.eb624","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":400,"wires":[["6a7768be.e5648"]]}]

You could try configuring the Debug node to also log to the console - that would flush straight away (at the point the Debug node received the message) and would rule in/out any issues with the comms link between runtime and editor getting jammed up.

Hi mudwalker, you have created a loop in your flow.

You need something in the flow to stop the feedback once you have done your task.

Try setting the "Command Resp" to a separate output to prevent the command coming through & looping back around

image

Alternatively, dont reply in your function node if the topic is pause-all or start-all

EDIT: only newer version of CRON+ can output command responses to a 2nd pin. What version do you have installed? If you can, then update. If you cant, update your function so something like below...

if(msg.topic=="start" || msg.topic=="pause"){
    return null; //stop the cmd response msg looping back
}

var cost = msg.payload;

if (cost !== 0) {
    msg.sendEmail = 1;
    msg.topic = "pause"
    msg.payload = "refetch"
}
else {
    msg.sendEmail = 0
    msg.topic = "start"
    msg.payload = "refetch"
}
return msg;

OK, thank you. Thank you both. I will have a play.

Version 1.0.3. Just playing now.

I am still seeing the same thing.

Command Resp - Send to separate output

Debug nodes to Console.txt (2.5 KB)

[Edit}. As long as you are aware, I shall now have a play. Thank you.

That should do the job as long as you haven't looped the 2nd output back.

Can you screen shot your flow & post an updated export?

Hi Steve,

Screenshots different between Production 1.0.6 and Beta beta.3 versions (Inject Node).



The flood would seem to be apparent in both Node-RED versions.

[{"id":"91dc1292.bb15b8","type":"function","z":"42c2a631.eb624","name":"Slot got value?","func":"var cost = msg.payload;\nif (cost !== 0) {\n    msg.sendEmail = 1;\n    msg.topic = \"pause\"\n    msg.payload = \"refetch\"\n}\nelse {\n    msg.sendEmail = 0\n    msg.topic = \"start\"\n    msg.payload = \"refetch\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":400,"wires":[["90939623.74a8c8","ebccfa55.f2fed","becebb3b.a72778"]]},{"id":"6a7768be.e5648","type":"cronplus","z":"42c2a631.eb624","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":310,"y":400,"wires":[["2e0e0a52.804b16","fb43f463.b29a"],["5703c6ce.16a408"]]},{"id":"90939623.74a8c8","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"sendEmail","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":400,"wires":[]},{"id":"2e0e0a52.804b16","type":"random","z":"42c2a631.eb624","name":"","low":"0","high":"1","inte":"true","property":"payload","x":480,"y":400,"wires":[["91dc1292.bb15b8"]]},{"id":"61ed2543.31c014","type":"inject","z":"42c2a631.eb624","name":"","props":[{"p":"payload"},{"p":"topic","v":"start","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"refetch","payloadType":"msg","x":90,"y":340,"wires":[["6a7768be.e5648"]]},{"id":"ebccfa55.f2fed","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":360,"wires":[]},{"id":"becebb3b.a72778","type":"delay","z":"42c2a631.eb624","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":400,"wires":[["6a7768be.e5648"]]},{"id":"fb43f463.b29a","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":340,"wires":[]},{"id":"5703c6ce.16a408","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":460,"wires":[]}]

I'm not seeing any issue (with your latest flow).

I do see a bunch of extraneous console logging (which I need to remove (next update)) but your flow doesnt seem to be running away - I am not seeing this delayed/flooding.

Can I suggest you give all your debug nodes unique names & when the condition occurs, screenshot or dump logs please.

Also, TBH, I am not 100% sure what your end goal is - can you import this & let me know if you are still seeing run-away condition...

[{"id":"ee5aa1e3.353ee","type":"function","z":"132ac715.5caf59","name":"Slot got value?","func":"var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"x":760,"y":260,"wires":[["bb8da836.15fe68","50b43ed3.ac44","7d2bd06c.431a8"],["1b8d87ea.54bbf8","636b1fc9.0c739"]]},{"id":"4f3f9f7c.192f3","type":"cronplus","z":"132ac715.5caf59","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":330,"y":260,"wires":[["77b68706.91dde8","a154bd39.bd9b1"],["44786d11.824164"]]},{"id":"bb8da836.15fe68","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1020,"y":280,"wires":[]},{"id":"77b68706.91dde8","type":"random","z":"132ac715.5caf59","name":"","low":"0","high":"1","inte":"true","property":"payload","x":580,"y":260,"wires":[["ee5aa1e3.353ee"]]},{"id":"4e7cd905.40a388","type":"inject","z":"132ac715.5caf59","name":"","topic":"","payload":"refetch","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":180,"wires":[["77b68706.91dde8"]]},{"id":"50b43ed3.ac44","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"topic","targetType":"msg","x":1010,"y":220,"wires":[]},{"id":"a154bd39.bd9b1","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":180,"wires":[]},{"id":"44786d11.824164","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":340,"wires":[]},{"id":"1b8d87ea.54bbf8","type":"link out","z":"132ac715.5caf59","name":"","links":["e8d024a6.9a19e8"],"x":835,"y":320,"wires":[]},{"id":"e8d024a6.9a19e8","type":"link in","z":"132ac715.5caf59","name":"","links":["1b8d87ea.54bbf8"],"x":195,"y":300,"wires":[["4f3f9f7c.192f3"]]},{"id":"636b1fc9.0c739","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"topic","targetType":"msg","x":1010,"y":360,"wires":[]},{"id":"7d2bd06c.431a8","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"sendEmail","targetType":"msg","x":1030,"y":160,"wires":[]}]

Hi Steve,

I have loaded your flow and will look deeper.

I really need to run this in the 'real world' to see what is happening. But like all these closed loop systems, things rely on other things over which we have no control, to either happen, or not happen!

As to what the flow does, I tried to explain in my first post, just not very well.
If some InfluxDB data obtained from an API is not available at a certain time, I need to trigger a fetch from the same API until the data does become available and is stored in the InfluxDB. Once the data is available, I need to stop accessing the API and also send an email with some of the accessed data in. This happens once a day and so the process starts again at the same time the next day.

This is all part of a far more extensive flow, just trying to keep things simple for developing the flow.

As I mentioned, my concern was that this might be a problem in beta.3 but gladly it seems not, so I am happy. I will carry on experimenting adding your tips into my flow. As ever, the pointers and tips are much appreciated. Even going to add the Context Data flow you gave me before to help me understand.

Thanks for the comments in the function! Very helpful for me!!

1 Like

I have now sat and had a play. Struggling but I think I may have found what is causing the problem.

Having cut the flow down to about as small as makes sense and then played around, I have 3 different nodes, effectively doing the same job (hopefully!).

<controlMsg "start"> is just this...
controlMsg.topic = "start"; //start cron
return [msg, controlMsg];

/Only controlMsg/ is the original function with this change on the last line...
return [controlMsg];

both would appear to work correctly.

As soon as I use your function that has been cut down /Slot got value?/, but with the original...
return [msg, controlMsg];

The problem occurs.

The data in the attached file is from the Context Data log.

Dell Precision M6700
Ubuntu 18.04 LTS
2 Jul 13:34:54 - [info] Node-RED version: v1.1.0
2 Jul 13:34:54 - [info] Node.js version: v12.18.1
2 Jul 13:34:54 - [info] Linux 5.3.0-61-generic x64 LE
2 Jul 13:34:55 - [info] Loading palette nodes
2 Jul 13:34:55 - [info] Dashboard version 2.22.1 started at /ui
2 Jul 13:34:56 - [warn] rpi-gpio : Raspberry Pi specific node set inactive

...and yes, I have updated to cronplus 1.0.4

[{"id":"29fe22bc.d8644e","type":"function","z":"1fe2e6f5.206b79","name":"controlMsg \"start\"","func":"controlMsg.topic = \"start\"; //start cron\n\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":450,"y":220,"wires":[[],["2f3d2f97.ae8dd"]]},{"id":"1c819368.f5f60d","type":"cronplus","z":"1fe2e6f5.206b79","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":190,"y":220,"wires":[["4b370e9f.ac9528","c09d8686.76d87"],[]]},{"id":"2f3d2f97.ae8dd","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["63a81466.153c44"],"x":595,"y":260,"wires":[]},{"id":"63a81466.153c44","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["2f3d2f97.ae8dd","66a7609e.3162c8","c37657d4.22ba28"],"x":55,"y":260,"wires":[["1c819368.f5f60d"]]},{"id":"4b370e9f.ac9528","type":"function","z":"1fe2e6f5.206b79","name":"Context log","func":"var contextname = \"cron_log\";\n\nvar log = flow.get(contextname) || [];\n\nvar logEntry = {\n    msg: RED.util.cloneMessage(msg),\n    time: new Date()\n}\n\nlog.push(logEntry);\n\nflow.set(contextname, log);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":160,"wires":[[]]},{"id":"c09d8686.76d87","type":"function","z":"1fe2e6f5.206b79","name":"Slot got value?","func":"var cost = 0;\n//var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":460,"y":280,"wires":[[],["66a7609e.3162c8"]]},{"id":"66a7609e.3162c8","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["71457be0.e7c1bc","63a81466.153c44"],"x":595,"y":320,"wires":[]},{"id":"89195fd9.10ea88","type":"function","z":"1fe2e6f5.206b79","name":"Only controlMsg","func":"var cost = 0;\n//var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":460,"y":340,"wires":[[],["c37657d4.22ba28"]]},{"id":"c37657d4.22ba28","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["63a81466.153c44"],"x":595,"y":380,"wires":[]}]

Cron_log.txt (9.5 KB)

1 Like

I see it now - gonna look into this ASAP

Thanks for your patience and feedback.

Thank you.

No rush from my end.

Hey @mudwalker

I believe I have found the issue and "contained it" for now (I have raised an issue on an underlying library).

Can you please update to V1.0.6 and let me know :crossed_fingers:

Thanks for your patience and support.

Steve.

Hi @Steve-Mcl ,

Thank you for your rapid response!! Much appreciated.

Ran my 'noddy' flow and all appears to be good. I will leave it running and let you know, but I don't doubt that if you have identified the problem, your workaround will be good!

Colin

1 Like