RailsCron: Trigger one time

Hi Kyle,

Thanks for your help so far. Now that I have it up and running, I’ve
some
behavior questions.

I want to trigger an event just one time at a future time. I’m using
some of
your sample code to try this, but the behavior of some combinations of
start,
every, and finish behave in some unpredictable ways.

 3  class RailsMaintainer
 4    include ActsAsBackground
 5    background :remove_sessions, :start => Time.now, :every => 

7.minutes,
:finish => 5.minutes.from_now
6
7
8 def self.remove_sessions
9 f = File.new(“testfile”, “a+”)
10 fmt = “%d %b %Y at %I:%M:%S %p”
11
12 f << "The time is: " << Time.new.strftime(fmt) << “\n”
13 f.close
14 end
15 end

My observations:

  1. start=0 (default), every=1.minute, finish=2.minutes.from.now
    • instead of starting immediately, it waits to the next whole minute,
      i.e.
      if I start it at 12:23:34, it waits until 12:24:00. I think it
      should
      start immediately
    • sometimes it triggers twice, which I think is correct. sometimes
      it
      triggers THREE times, which I don’t understand why
  2. start=1.minute.from_now, every=1.minute, finish=2.minutes.from.now
    • it started at a second granularity, 12:23:35, instead of waiting to
      the
      next minute, which is correct but seems inconsistent with the
      default
      start behavior. It also triggers twice, which it shouldn’t because
      of
      the finish time.
  3. start=1.minute.from_now, every=1.minute, finish=1.minute.from.now
    • tried this to just trigger one time. Sometimes it triggered,
      sometimes
      it didn’t. There seems to be a race condition.
  4. start=Time.now, every=7.minutes, finish=5.minutes.from_now
    • Presumably, this should execute once. And indeed, it does. But
      then
      if I do RailsMaintainer.new again, it never triggers again. I have
      to
      restart the RailsCron process.

Requests:

  1. An option to trigger a job 1 time at a particular time
  2. When you get the time, a more detailed description of the timing
    would be
    very helpful. The biggest question for us is how sure can we be of when
    an
    event triggers? We’d like to say, send an email reminder at 6:23:15 and
    have
    the process kick off at that second, not 6:24:00 or 6:24:15.
  3. If we restart the RailsCron process (perhaps because the shared host
    restarts
    their unstable system), it’s unclear when the next events will trigger.
    So if I
    say update my file every 10 minutes, and 3 minutes after my last update
    the
    server restarts, when it comes up, does the next event occur immediately
    (00:13), or at the “correct” interval (00:20), or after 10 more minutes
    (00:23).
    In the database, it doesn’t look like you store the last trigger time,
    which I
    think would be helpful in creating more predictable behavior.

I know I’m asking a lot of questions, but I’m seriously trying to use
your
plugin. If these kinds of use cases are not in your plans to support,
please
let me know.

Thanks,
Jake

On 2/24/06, Jake [email protected] wrote:

 4    include ActsAsBackground
14    end
15  end

My observations:

  1. start=0 (default), every=1.minute, finish=2.minutes.from.now
    • instead of starting immediately, it waits to the next whole minute, i.e.
      if I start it at 12:23:34, it waits until 12:24:00. I think it should
      start immediately
    • sometimes it triggers twice, which I think is correct. sometimes it
      triggers THREE times, which I don’t understand why

:start => 0 starts at the Unix epoch. You want start => Time.now.
The three times thing is perhaps because the running range is
inclusive of the finish time, so start => 0, every => 5, :finish =>10,
triggers at 0, 5, 10.

  1. start=1.minute.from_now, every=1.minute, finish=2.minutes.from.now
    • it started at a second granularity, 12:23:35, instead of waiting to the
      next minute, which is correct but seems inconsistent with the default
      start behavior. It also triggers twice, which it shouldn’t because of
      the finish time.

See previous.

  1. start=1.minute.from_now, every=1.minute, finish=1.minute.from.now
    • tried this to just trigger one time. Sometimes it triggered, sometimes
      it didn’t. There seems to be a race condition.

Ok, I’ll look at that.

  1. start=Time.now, every=7.minutes, finish=5.minutes.from_now
    • Presumably, this should execute once. And indeed, it does. But then
      if I do RailsMaintainer.new again, it never triggers again. I have to
      restart the RailsCron process.

Requests:

  1. An option to trigger a job 1 time at a particular time

If you add a RailsCron model entry manually, and have the called
method delete the entry, that should do it.

think would be helpful in creating more predictable behavior.

I know I’m asking a lot of questions, but I’m seriously trying to use your
plugin. If these kinds of use cases are not in your plans to support, please
let me know.

That’s fine. My personal needs revolve around running
timing-insensitive background processes like clearing sessions, and
sending email out of a queue. I just want them to run in the
background occasionally. That’s why I haven’t caught your issues yet.

I want RailsCron to work for these tight timing issues. I think that
the first step is to establish a unit test suite, but that’s tricky to
do right for this, and I haven’t had time recently. Let’s talk over
your concerns. Send me a email or ping me on AOL IM: rbyhaxr

Thanks,
Jake


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261