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)?
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?
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)?
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?
There is: Cron jobs on *NIX or Task Scheduler on Windows. You have no
guarantee that your program is running, and Cron/Task Scheduler can
run tasks that *have* to occur, even after the original time has
passed.
···
On Tue, Jun 28, 2011 at 8:58 PM, Chad Perrin <code@apotheon.net> wrote:
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?
--
Phillip Gawlowski
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz
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).
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)?
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?
I need something a little more portable than the options you provided,
though I appreciate the suggestions. Someone else in the thread pointed
me at a gem that seems to do what I need, so I'll look into that.
···
On Wed, Jun 29, 2011 at 04:22:22AM +0900, Eric Wong wrote: