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

Brett Walker lapomme00 at gmail.com
Mon Aug 7 09:29:19 EDT 2006

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

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]

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.


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

More information about the Backgroundrb-devel mailing list