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:
- 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
- instead of starting immediately, it waits to the next whole minute,
- 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.
- it started at a second granularity, 12:23:35, instead of waiting to
- 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.
- tried this to just trigger one time. Sometimes it triggered,
- 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.
- Presumably, this should execute once. And indeed, it does. But
Requests:
- An option to trigger a job 1 time at a particular time
- 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. - 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