# What's the most reasonable way to do something seasonal in racket

**URL:** <https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [February 28, 2022, 9:30am UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746 "2022-02-28T09:30:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hanson](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hanson/32/388_2.png) [@Hanson](https://racket.discourse.group/u/Hanson)\
**Post date:** [February 28, 2022, 9:30am UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746/1 "2022-02-28T09:30:59Z")

</div>

For example, check if a connection is still alive every 1 hour and reconnect if is not.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [February 28, 2022, 3:46pm UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746/2 "2022-02-28T15:46:11Z")

</div>

Are you using an operating system that supports cron jobs? That's not a very racket-y solution, but it's certainly the simplest. You can also set up a long-running process, and run it in the background. ... But then you're going to want something to start it back up if it halts, or on reboot, and then you're off into daemon-land.

Basically: tell us more about the platform you're running on?

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [February 28, 2022, 9:39pm UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746/3 "2022-02-28T21:39:29Z")

</div>

As @jbclements said you might want to consider outsourcing the dependable scheduler aspect to the operating system.

But let's say you already have some Racket process that is already doing various other things. And you're already satisfied with however you're ensuring that keeps running a long time.

In that case:

1. You can spawn a thread to loop and `sleep`.
2. You can spawn a thread to loop, creating an `alarm-evt` each time, and `sync`-ing for that to be ready. (Morally equivalent to 1, but a good setup for 3...)
3. If you already have some thread that is synchronizing on other events, you can add a new `alarm-evt` to the set of things on which it `sync`s.

Keep in mind that if a thread raises an uncaught exception, it will terminate. So, you probably want to wrap your reconnect-if-necessary in `with-handlers` and do something you think is reasonable (just try again in an hour, try again sooner, etc.).

* * *

p.s. Instead of `sleep` or `alarm-evt` you could probably use `system` to run `raco setup` to rebuild all documentation, which seems like a not unreasonable definition of "1 hour" to me. 😉

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [March 1, 2022, 4:03pm UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746/4 "2022-03-01T16:03:31Z")

</div>

> [@greghendershott](#):
>
> Keep in mind that if a thread raises an uncaught exception, it will terminate. So, you probably want to wrap your reconnect-if-necessary in `with-handlers` and do something you think is reasonable (just try again in an hour, try again sooner, etc.).

[self-plug] The [majordomo2](https://docs.racket-lang.org/majordomo2/index.html) package will handle monitoring and restarts for you, as well as carrying data across the restarts. [/self-plug]

---

<div class="post-metadata">

**Author:** ![Hanson](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hanson/32/388_2.png) [@Hanson](https://racket.discourse.group/u/Hanson)\
**Post date:** [March 3, 2022, 11:25am UTC](https://racket.discourse.group/t/whats-the-most-reasonable-way-to-do-something-seasonal-in-racket/746/5 "2022-03-03T11:25:17Z")

</div>

What about [Task Server](https://docs.racket-lang.org/tasks) ?
