[Backgroundrb-devel] repeat_every doesn't tie in with first_run...

Ezra Zygmuntowicz ezmobius at gmail.com
Mon Aug 7 11:15:16 EDT 2006

	Yeah I agree with Brett. If we are going to have a start time like  
we do we ought to be calculating the intervals so they line up to the  
correct time. Perhaps I can steal that method from rails cron ;) I  
hope to have some time later today to work on the plugin. I have a  
few features lined up that I need to release. I will add this to the  
list and see what I can come up with.


On Aug 7, 2006, at 6:29 AM, Brett Walker wrote:

> Hhhmm...I still disagree.   A 24 hour cycle was not a good example.
> Suppose I want it run every 6 hours.  2am, 8am, 2pm, 8pm.  Since we
> don't know when backgroundrb is going to be started, it's a convuluted
> calculation for first_run to line up with one of the run times, unless
> you put it at 2am tomorrow.  But that means it doesn't run at all
> today.
> The best way is to set it to 2am today, and calculate the period based
> off of the start time.  Railscron takes care of it like this:
>   def should_run_now
>     now = Time.now.to_i
>     return false if self.start && self.start > now
>     return false if self.finish && self.finish < now
>     start = self.start
>     every = self.every || 1.day
>     proximity = (now - start) % every
>     return proximity < @@options[:sleep]
>   end
> The difference between Time.now and the start time modded with the
> period.  As long as the remainder falls within the sleep period, it
> kicks off.  Your going to get within @@options[:sleep] seconds of the
> real time you wanted.
> Cheers,
> Brett
> On 8/7/06, Michael Siebert <info at siebert-wd.de> wrote:
>> That Behaviour is absolutely OK, since it starts the job when  
>> Time.now >
>> first_start. Time.now.beginning_of_day is 0:00 TODAY, meaning 14  
>> hours ago
>> (at least here in Germany). The only way to work around that is to  
>> use
>> Time.now.tomorrow.beginning_of_day meaning 0:00 tonight. I
>> think this can be improved in some later version.
>> 2006/8/7, Brett Walker <lapomme00 at gmail.com>:
>> Ezra,
>> Sorry for inundating the list.  In using the autostart, repeat_every,
>> and first_run, I noticed a behaviour I didn't expect.
>> I would like the job to run starting at 2am, and then every 24 hours.
>> So I set first_run to Time.now.beginning_of_day + 2.hours, and
>> repeat_every to 24.hours.
>> The problem is if backgroundrb starts up at 6am (due to a code change
>> or server bump), then the process runs immediately (because first_run
>> < Time.now), and then runs every 24 hours from that time, so 6am  
>> every
>> day.  I was expecting more cron-ish behaviour, where it would  
>> start at
>> the first_run time and repeat based on that initial time.
>> Is this the proper behaviour?  Personally, I like the cron style
>> better - it gives me tighter control, which might be required for
>> better resource utilization.  If I want it to start running
>> immediatley, I can put in first_run Time.now.
>> Thoughts?
>> Cheers,
>> Brett
>> _______________________________________________
>> Backgroundrb-devel mailing list
>>  Backgroundrb-devel at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>> --
>>  Michael Siebert <info at siebert-wd.de>
>> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel

More information about the Backgroundrb-devel mailing list