From: Eric Wong Date: 2011-06-29T04:22:22+09:00 Subject: Re: clock-scheduled operations Chad Perrin wrote: > Obviously, scheduling something to happen every foo seconds is easy. > What is a reasonably performant, simple way to schedule an operation to > occur at a particular time of day (preferably specified by a particular > time zone)? If it has to be within a long-running program: You can install a signal handler and have cron signal the process. I don't know of anything that takes care of timezones/calculations for you, but... > The first thing that comes to my mind is checking Time.now, checking the > time between that and the desired time of day, then spawn a thread that > sleeps for that length of time (because I need the program to do other > things in the meantime). Is there a better way to do this? Cool.io and EventMachine both expose timer functionality which should be reasonably portable across different *nixes. If you're only targetting recent-ish Linux systems, the sleepy_penguin[1] library exposes TimerFD as an IO object which you can IO.select/poll/epoll on. This functionality is only lightly-tested, so feedback is welcome (I'm the maintainer). [1] http://bogomips.org/sleepy_penguin/ -- Eric Wong