Clock-scheduled operations

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?

···

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

cron

···

On Jun 28, 2011, at 11:58 , 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)?

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

[1] sleepy_penguin - Linux I/O events for Ruby

···

Chad Perrin <code@apotheon.net> wrote:

--
Eric Wong

http://rufus.rubyforge.org/rufus-scheduler/ or as Ryan has written cron
or launchd on osx.

All the best, Sandor Szücs
- --

···

On Jun 28, 2011, at 8:58 PM, 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)?

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?

Thanks. I'll look into that.

···

On Wed, Jun 29, 2011 at 04:58:09AM +0900, Sandor Szuecs wrote:

http://rufus.rubyforge.org/rufus-scheduler/ or as Ryan has written cron
or launchd on osx.

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

[snip]

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:

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]