# Schedule something for 2 hours in future?

**URL:** <https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329>\
**Category:** General\
**Created:** [19 March 2020 21:22 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329 "2020-03-19T21:22:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettyj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brettyj/32/12049_2.png) [@brettyj](https://discourse.nodered.org/u/brettyj)\
**Post date:** [19 March 2020 21:22 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329/1 "2020-03-19T21:22:56Z")

</div>

Hey,

Wondering if anyone has a solution to this.

So I have an event that when fires uses a timeout node to countdown for 2 hours before I need to turn off the device. It works fine, but the problem with any timeout that is longer than a few minutes is, that if I deploy in the meantime, or restart the server etc, the timeout is lost.

So what I need is a persistent timeout (like using a data store in the change mode), or a way to dynamically create an inject node or something that fires at a certain time (and then gets deleted).

What's the best way to handle this?

I'm thinking that I could set the finish time (now + 2 hours) to a persistant data store, through change, and set up an inject that fires after deploy / start that reads that, sees if a timer was active, and if so resets the timer with (end time - now). Should work, but wondering if there's a better solution I'm missing.

Thanks

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [19 March 2020 21:59 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329/2 "2020-03-19T21:59:56Z")

</div>

I think you have already solved your problem! Think about how to implement it!

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 March 2020 22:09 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329/3 "2020-03-19T22:09:48Z")

</div>

There are some “fun” edges cases to this sort of problem, but the basic principle is right.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 March 2020 22:14 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329/4 "2020-03-19T22:14:29Z")

</div>

Or you could use cron-plus and configure it dynamically for the right time. Would have to cope with being switched off over the time it should trigger though

---

<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:** [18 May 2020 22:29 UTC](https://discourse.nodered.org/t/schedule-something-for-2-hours-in-future/23329/5 "2020-05-18T22:29:20Z")

</div>

Closed on 18 May 2020 22:29 UTC

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