Timers, scheduling and Ruby

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

I'm still catching up to this thread but FWIW I am always interested in
making Runt more useful and functional. If I understand the above
correctly, then you'd like a next_time method returning a
Date/DateTime/Time (or whatever) that indicates the next occurrence of
this expression?

Matt

__mlipper__at__gmail_dot_com__

···

On 12/1/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Fri, 1 Dec 2006, Pit Capitain wrote:

Bingo!

From the tutorial example ...

last_thursday = DIMonth.new(Last_of,Thursday)
august = REYear.new(8)
expr = last_thursday & august

expr.next_time #=> or some equally clever method name

Here returns the Time object that represents the last Thursday in
August -- probably midnight since that is when Thursday starts.

mon_wed_fri = DIWeek.new(Mon) | DIWeek.new(Wed) | DIWeek.new(Fri)
mon_wed_fri.next_time

Since today is Friday, this example would return the Time object that
represents the next Monday from today.

Maybe just "next" instead of "next_time" ??

Any chance of getting Runt and Chronic to play nicely together?

Blessings,
TwP

···

On 12/1/06, Lipper, Matthew <Mlipper@doitt.nyc.gov> wrote:

>
> On 12/1/06, ara.t.howard@noaa.gov <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
>

I'm still catching up to this thread but FWIW I am always interested in
making Runt more useful and functional. If I understand the above
correctly, then you'd like a next_time method returning a
Date/DateTime/Time (or whatever) that indicates the next occurrence of
this expression?

here's what i'd like

   inclusive_endpoint = Time.now + 7.days

   runt.next_times inclusive_endpoint #=> array of all times covered between
                                       # now and endpoint, 'now' should be an
                                       # optional parameter so multiple calls
                                       # can be made transactional, eg

···

On Sat, 2 Dec 2006, Lipper, Matthew wrote:

I'm still catching up to this thread but FWIW I am always interested in
making Runt more useful and functional. If I understand the above correctly,
then you'd like a next_time method returning a Date/DateTime/Time (or
whatever) that indicates the next occurrence of this expression?

                                       #
                                       # runt.next_times inclusive_endpoint, 'now' => Time.now
                                       # runt.next_times inclusive_endpoint, :now => Time.now
                                       #

that way it's easy to do

   loop{
     now = Time.now

     inclusive_endpoint = now + sleep_interval

     runts.each do |runt|
       times = runt.next_times inclusive_endpoint, :now => now
       schedule_all_events times
     end

     sleep_until inclusive_endpoint
   }

make sense?

thanks for a great lib btw!

-a
--
if you want others to be happy, practice compassion.
if you want to be happy, practice compassion. -- the dalai lama