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

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

3 Likes

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?

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 syncs.

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. :wink:

3 Likes

[self-plug] The majordomo2 package will handle monitoring and restarts for you, as well as carrying data across the restarts. [/self-plug]

4 Likes

What about Task Server ?