# Re: Timers, scheduling and Ruby

**URL:** <https://www.ruby-forum.com/t/re-timers-scheduling-and-ruby/77940>\
**Category:** Ruby\
**Created:** [December 1, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/re-timers-scheduling-and-ruby/77940 "2006-12-01T19:37:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LipperS\_Matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@LipperS\_Matthew](https://www.ruby-forum.com/u/LipperS_Matthew)\
**Post date:** [December 1, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/re-timers-scheduling-and-ruby/77940/1 "2006-12-01T19:37:16Z")

</div>

> determine the time of
> 
> > be scheduled for the next minute ‘tick’.
> 
> What is needed to make Runt work for a scheduler is a next\_time method
> 
> 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**

---

<div class="post-metadata">

**Author:** ![LipperS\_Matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@LipperS\_Matthew](https://www.ruby-forum.com/u/LipperS_Matthew)\
**Post date:** [December 1, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/re-timers-scheduling-and-ruby/77940/2 "2006-12-01T20:25:24Z")

</div>

On 12/1/06, Lipper, Matthew [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > determine the time of
> > 
> > > be scheduled for the next minute ‘tick’.
> > 
> > What is needed to make Runt work for a scheduler is a next\_time method
> > 
> > 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?

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

---

<div class="post-metadata">

**Author:** ![LipperS\_Matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@LipperS\_Matthew](https://www.ruby-forum.com/u/LipperS_Matthew)\
**Post date:** [December 1, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/re-timers-scheduling-and-ruby/77940/3 "2006-12-01T20:41:28Z")

</div>

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?

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