From: Tim Pease Date: 2006-12-02T01:24:19+09:00 Subject: Re: Timers, scheduling and Ruby On 12/1/06, ara.t.howard@noaa.gov wrote: > On Fri, 1 Dec 2006, Pit Capitain wrote: > > > ara.t.howard@noaa.gov schrieb: > >> how bout this as the time spec? > >> > >> http://runt.rubyforge.org/ > > > > Ara, this would be nice, but I think it's difficult to determine the time of > > the next event with Runt's temporal expressions. I'm sure you don't want to > > call Runt::TExpr#include? every n seconds. > > indeed. this is the only major design flaw. still, if one assumes a > granualrity of not more than 60s (ala cron) then this approach isn't too bad. > between the dates/include methods one can determine apriori if an event should > be scheduled for the next minute 'tick'. > > i'm assuming there is either a solution implied in the code or that one can be > added without too much trouble - the bulk of the work has already been done in > this lib, so even if it isn't there now, i'm sure a solution will present > itself. > > now. what do you suggest? > Runt looks nice. Another package is Chronic. It was part of the natural language processing presentation at RubyConf this year. All Chronic does, though, is take human "fuzzy" times and turns them into actual Time objects. Chronic.parse "next Thursday at seven am" #=> Time object http://rubyforge.org/projects/chronic/ What is needed to make Runt work for a scheduler is a next_time method that would return the next Time that this event should happen given Time.now. The scheduler then maintains a queue of the "next time" for all events and pulls them from the queue in order. When an event runs, the last thing it does is pulls the next_time from Runt and adds that to the queue (in the proper location). The scheduler thread then sleeps for N seconds where N is the time till the next event in the queue needs to happen. So, maybe a combination of Chronic (to get the nice human readable format) and Runt (to keep track of recurring events) would work? TwP