Trying not to go OT from this thread....
The node readme is very basic, and has no example flow.
@Colin I'm struggling to understand how this node would work in a flow environment?
Paul
Trying not to go OT from this thread....
The node readme is very basic, and has no example flow.
@Colin I'm struggling to understand how this node would work in a flow environment?
Paul
I will post a flow in the morning, is late here.
Here is an example of using node-red-contrib-semaphore. A semaphore is like a token used on a single track railway to ensure only one train is on the line at a time. The semaphore take node allows the semaphore to be taken or acquired, once that happens then messages will be queued until the semaphore is released in the semaphore leave node. The effect is that the next message is not allowed to pass until the protected task completes.
One thing you have to make sure is that every exit from the task does send a message (and only one) to the semaphore leave node, otherwise the flow will grind to a halt. It may therefore be a good idea to include a catch node as I have done in case the task generates an error and does not send any output.
[{"id":"52da7849.5a04d","type":"semaphore-take","z":"6dc690a3.1abc88","config":"f1723a93.b1fee","name":"","x":208.5,"y":360,"wires":[["b742bf19.8905a"]]},{"id":"c992389.f77ad48","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90.5,"y":295,"wires":[["c1900da7.2f2828"]]},{"id":"c1900da7.2f2828","type":"function","z":"6dc690a3.1abc88","name":"Generate multiple messages","func":"msg1 = {payload: \"message 1\"}\nmsg2 = {payload: \"message 2\"}\nmsg3 = {payload: \"message 3\"}\nmsg4 = {payload: \"message 4\"}\nreturn [[msg1,msg2,msg3,msg4]]","outputs":1,"noerr":0,"x":290.5,"y":296,"wires":[["52da7849.5a04d"]]},{"id":"f04b86a1.1245d8","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":689,"y":434,"wires":[]},{"id":"b742bf19.8905a","type":"delay","z":"6dc690a3.1abc88","name":"Task that should only run message at a time","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":489.5,"y":359,"wires":[["8f1b395a.fda968","f04b86a1.1245d8"]]},{"id":"8f1b395a.fda968","type":"semaphore-leave","z":"6dc690a3.1abc88","config":"f1723a93.b1fee","name":"","x":456.5,"y":472,"wires":[[]]},{"id":"c85afe13.e94a4","type":"catch","z":"6dc690a3.1abc88","name":"","scope":["b742bf19.8905a"],"x":351.5,"y":402,"wires":[["8f1b395a.fda968"]]},{"id":"b1fb2135.8e2728","type":"comment","z":"6dc690a3.1abc88","name":"node-red-contrib-semaphore example","info":"","x":458.5,"y":257,"wires":[]},{"id":"f1723a93.b1fee","type":"semaphore-config","z":"","name":"My semaphore","capacity":"1"}]
Thanks Colin. I was almost there!!!
And yes it does seem easier to use than node-red-contrib-simple-message-queue
so I'll probably change to using it.
Paul