# Dynamic Change to \[Inject Node?\] Repeat Interval?

**URL:** <https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191>\
**Category:** General\
**Created:** [3 April 2023 10:28 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191 "2023-04-03T10:28:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [3 April 2023 10:28 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/1 "2023-04-03T10:28:24Z")

</div>

I have an Inject node set to repeat every minute. This works fine when the "looping" flow doesn't need to do something that takes longer than around 20 seconds to complete. However, when the overall flow has not completed in time this causes problems the next time it is called (as some states are not as anticipated).

I considered putting a conditional delay so that the next loop is delayed after it's triggered, but this would only cause problems to mount up as AFAIK the inject trigger would be fired even when the previous run has not completed.

Obviously, I could permanently lengthen the repeat interval (and AFAIK I can't do this dynamically), but is there a better way to manage such a 'loop'?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 April 2023 11:18 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/2 "2023-04-03T11:18:22Z")

</div>

Have a look at the CRON+ node, it should let you do what you want.

---

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [3 April 2023 11:39 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/3 "2023-04-03T11:39:18Z")

</div>

Ah yes! Thank you!

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 April 2023 11:39 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/4 "2023-04-03T11:39:20Z")

</div>

There are various gate nodes that you can use to throw away any injects until your processing is complete.

An example using node-red-contrib-simple-gate:

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d8ce1a2fe4b263398c3abfd64392858fb4a7597.jpeg)

```auto
[{"id":"f953b3eb54ae90f8","type":"inject","z":"ebe721b4236762ee","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":140,"wires":[["e3ffef82238a93a0"]]},{"id":"e3ffef82238a93a0","type":"gate","z":"ebe721b4236762ee","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":330,"y":140,"wires":[["26e67434989ae055","c9316a8dc6c3de34"]]},{"id":"26e67434989ae055","type":"change","z":"ebe721b4236762ee","name":"Close gate","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":200,"wires":[["e3ffef82238a93a0"]]},{"id":"c9316a8dc6c3de34","type":"delay","z":"ebe721b4236762ee","name":"Some prolonged processing","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":600,"y":140,"wires":[["248644a4404e4826","61b80d77d0769562"]]},{"id":"61b80d77d0769562","type":"debug","z":"ebe721b4236762ee","name":"debug 319","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":140,"wires":[]},{"id":"248644a4404e4826","type":"change","z":"ebe721b4236762ee","name":"Open gate","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":80,"wires":[["e3ffef82238a93a0"]]}]

```

---

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [3 April 2023 11:40 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/5 "2023-04-03T11:40:15Z")

</div>

Thanks. That looks like it might be a more straightforward way of doing what I need.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2023 12:01 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/6 "2023-04-03T12:01:35Z")

</div>

> [@lorccan](#):
>
> I could permanently lengthen the repeat interval (and AFAIK I can't do this dynamically), but is there a better way to manage such a 'loop'?

The best solution (in an event based env like Node) is "dont loop". There is almost always a better way.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 June 2023 12:01 UTC](https://discourse.nodered.org/t/dynamic-change-to-inject-node-repeat-interval/77191/7 "2023-06-02T12:01:58Z")

</div>

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