Cron-plus and next event

Hi!

I'm using the cron-plus node. My question: is there a way to get the time and date of the event that will execute next? Like in the status shown in the editor?

Background: I'd like to use the cron-pus node in a subflow and have the same status. That's why I need to feed the next execution time into the status node of the subflow. The coloured circle/dot would be nice but is not a "must have".

My approach would be to get all nextDate fields by using command status-all, then sorting and taking the first/next one... but maybe there's an easier solution.

Thanks in advance!

if it is shown in the existing status - then the status node should be able to get it.

Hmmm, not really. The flow looks like
image

The subflow is
image

So, what I see in the flow is - after execution - the trigger time stamp. But even when cron is waiting for the next execution, I cannot see the status
image

Hi .. maybe something like this ?

Example Flow :

[{"id":"2626dc64a84cde56","type":"subflow","name":"Subflow 1","info":"","in":[{"x":60,"y":80,"wires":[{"id":"b1945ef169f97d71"}]}],"out":[{"x":340,"y":80,"wires":[{"id":"b1945ef169f97d71","port":0}]}],"status":{"x":340,"y":200,"wires":[{"id":"d45f812abe56c395","port":0}]}},{"id":"b1945ef169f97d71","type":"cronplus","z":"2626dc64a84cde56","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 11 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"schedule2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 7 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule3","topic":"schedule3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 4 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule4","topic":"schedule4","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 8 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":200,"y":80,"wires":[[]]},{"id":"d45f812abe56c395","type":"status","z":"2626dc64a84cde56","name":"","scope":["b1945ef169f97d71"],"x":140,"y":200,"wires":[[]]},{"id":"0ed13df44b941f86","type":"inject","z":"af25975e21b17ff4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"status-all\"}","payloadType":"json","x":130,"y":820,"wires":[["2298c4c3d9190ceb"]]},{"id":"03a93b36c1d1f757","type":"debug","z":"af25975e21b17ff4","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":410,"y":760,"wires":[]},{"id":"861798c9e03a035c","type":"change","z":"af25975e21b17ff4","name":"Jsonata sort","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sort(**.nextDateTZ)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":820,"wires":[["e79ed1e27d32b02f","35de6d23a0650fe0"]]},{"id":"e79ed1e27d32b02f","type":"debug","z":"af25975e21b17ff4","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":760,"wires":[]},{"id":"2298c4c3d9190ceb","type":"subflow:2626dc64a84cde56","z":"af25975e21b17ff4","name":"","env":[],"x":320,"y":820,"wires":[["03a93b36c1d1f757","861798c9e03a035c"]]},{"id":"35de6d23a0650fe0","type":"debug","z":"af25975e21b17ff4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":820,"wires":[]}]

Yes. No need to read the status text (which changes as processes are run - so is unreliable)

Use the command topic status-all then sort the results and return the newest entry...

[{"id":"591a56224f88062c","type":"cronplus","z":"bec69dbd.8d622","name":"4 schedules","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 11 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"schedule2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 7 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule3","topic":"schedule3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 4 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule4","topic":"schedule4","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 8 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":950,"y":1700,"wires":[[],["48a136f34f3ca57b"]]},{"id":"9dc73aeb28848ea0","type":"inject","z":"bec69dbd.8d622","name":"status-all","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"status-all","x":760,"y":1700,"wires":[["591a56224f88062c"]]},{"id":"eac3f4b63cf580ee","type":"function","z":"bec69dbd.8d622","name":"get next to run","func":"if (msg.payload.result && msg.payload.result.length) {\n\n    const sorted = msg.payload.result.sort(function (a, b) {\n        if (a.status.nextDate < b.status.nextDate) return -1;\n        if (a.status.nextDate > b.status.nextDate) return 1;\n        return 0;\n    });\n\n    if (sorted && sorted.length) {\n        msg.payload = {\n            config: sorted[0].config,\n            status: sorted[0].status\n        } \n        return msg;\n    }\n\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":1760,"wires":[["31de359bc693742e"]]},{"id":"31de359bc693742e","type":"debug","z":"bec69dbd.8d622","name":"Next to run","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1330,"y":1760,"wires":[]},{"id":"48a136f34f3ca57b","type":"switch","z":"bec69dbd.8d622","name":"status-all command response?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"status-all","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":1760,"wires":[["eac3f4b63cf580ee"]]}]

1 Like

apologies - I thought that showed the next event to run - and if it changed that would be a good thing rather than having to poll...

It does Dave, but it also (momentarily) shows other info like Done: xxxxx (see GIF below)

This is (relatively) easy to capture also (without polling)...

MbJgPp9zH6

[{"id":"591a56224f88062c","type":"cronplus","z":"bec69dbd.8d622","name":"4 schedules","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 11 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"schedule2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 7 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule3","topic":"schedule3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 4 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule4","topic":"schedule4","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 8 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":950,"y":1700,"wires":[["3fd8d85705e239a6","28d9c59aa18e7efc"],["48a136f34f3ca57b"]]},{"id":"9dc73aeb28848ea0","type":"inject","z":"bec69dbd.8d622","name":"status-all","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"status-all","payloadType":"str","x":520,"y":1700,"wires":[["dad662673acb025a"]]},{"id":"eac3f4b63cf580ee","type":"function","z":"bec69dbd.8d622","name":"get next to run","func":"if (msg.payload.result && msg.payload.result.length) {\n\n    const sorted = msg.payload.result.sort(function (a, b) {\n        if (a.status.nextDate < b.status.nextDate) return -1;\n        if (a.status.nextDate > b.status.nextDate) return 1;\n        return 0;\n    });\n\n    if (sorted && sorted.length) {\n        msg.payload = {\n            config: sorted[0].config,\n            status: sorted[0].status\n        } \n        return msg;\n    }\n\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":1780,"wires":[["31de359bc693742e"]]},{"id":"31de359bc693742e","type":"debug","z":"bec69dbd.8d622","name":"Next to run","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload.config.name","statusType":"msg","x":1210,"y":1780,"wires":[]},{"id":"48a136f34f3ca57b","type":"switch","z":"bec69dbd.8d622","name":"status-all command response?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"status-all","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":770,"y":1780,"wires":[["eac3f4b63cf580ee"]]},{"id":"b74ae0acba34c49a","type":"inject","z":"bec69dbd.8d622","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"schedule1","payloadType":"str","x":740,"y":1640,"wires":[["591a56224f88062c"]]},{"id":"dad662673acb025a","type":"change","z":"bec69dbd.8d622","name":"set topic status-all","rules":[{"t":"set","p":"topic","pt":"msg","to":"status-all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1700,"wires":[["591a56224f88062c"]]},{"id":"e6fc5cfe51bdf45a","type":"link in","z":"bec69dbd.8d622","name":"","links":["3fd8d85705e239a6"],"x":555,"y":1660,"wires":[["dad662673acb025a"]]},{"id":"3fd8d85705e239a6","type":"link out","z":"bec69dbd.8d622","name":"","links":["e6fc5cfe51bdf45a"],"x":1075,"y":1660,"wires":[]},{"id":"28d9c59aa18e7efc","type":"debug","z":"bec69dbd.8d622","name":"Schedule","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1200,"y":1700,"wires":[]}]

So I understand it like this:

  1. I issue a status-all command, sort and show the first entry
  2. Whenever the node triggers, I issue this command again and get the next event

To use it in a subflow with input (e.g. to add a schedule), I had to add some logic to the flow, now it looks like that:


Otherwise it didn't work as expected. After an input there is nothing in the "output" debug node. Thus there is no status update. Or did I miss something?

And one additional question: Do I need a delay before my "update status after input received" link? Or is a topic input to the cron-plus node always processed after the payload? Or should the change node even remove the payload before setting the topic to status-all? I'm a little bit confused...

Looking at what you have there, your only intention is to display the next event on the status of the subflow instance - am i correct?

If that is all you need then instead of querying the schedules and sorting etc, simply use a status node (pointed at the cron node) and feed that to the status subflow output.


If you are inputting a schedule and requesting status at the same time, it will depend on which message arrives first. This is easy to counter with a short delay (50ms is more than enough)

Ahhh, the status node!!! Sometimes I just don't see the easy things! Thanks a lot!

Maybe I need some more coffee... A few moments ago I fed the output of the status node to the inbput of the cron node instead of to the status output of the subflow, bad idea... :grimacing:

could swear that is what I suggested yesterday :wink:

1 Like

My bad! You're right of course!

Must be my English, I'm from Germany. I just didn't understand your answer

When I read "status node" I thought of the status output node of the subflow, but you were talking about the status node from the palette... apparently I need to read answers more carefully :flushed:

not a problem - I was just teasing Steve

1 Like

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