Forum: Ruby on Rails periodically call remote is not my friend

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
903de3fe51f14392609e28e82e1b1c6c?d=identicon&s=25 Rick Fiorentino (rickf)
on 2007-07-14 00:11
Hi All,

I have a table in a view (its a partial) that is updated from every 5
seconds as the shortest frequency to as long as manual by the user based
on some configuration parameters.

With the periodically_call_remote it appears as though I am getting
subsequent calls going out even though I have one or more pending?
Although the call is asynchronous I thought calls went out only when the
completion of previous calls occurs. Meaning, even if my interval might
have been exceeded it won't send out the next request until the previous
comes in. This seems an issue as the load on the server increases the
probability of missing the interval window increases as well.

Is this not true? If not, how does one manage avoiding parallel calls?
Would I be better off to dynamically create a single periodic call per
generation of the partial that is updated as a result of the AJAX call?

Also, if I have a pending call and the user moves to a different page
before the response comes in I get prototype errors in the firebug
console. None of them cause crashes etc, but I thought this would be
benign?

Any information is appreciated on any of these points.

Best Regards,
Rick
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (squeegy)
on 2007-07-14 06:23
Rick Fiorentino wrote:
> Hi All,
>
> I have a table in a view (its a partial) that is updated from every 5
> seconds as the shortest frequency to as long as manual by the user based
> on some configuration parameters.
>
> With the periodically_call_remote it appears as though I am getting
> subsequent calls going out even though I have one or more pending?
> Although the call is asynchronous I thought calls went out only when the
> completion of previous calls occurs. Meaning, even if my interval might
> have been exceeded it won't send out the next request until the previous
> comes in. This seems an issue as the load on the server increases the
> probability of missing the interval window increases as well.
>
> Is this not true? If not, how does one manage avoiding parallel calls?
> Would I be better off to dynamically create a single periodic call per
> generation of the partial that is updated as a result of the AJAX call?
>
> Also, if I have a pending call and the user moves to a different page
> before the response comes in I get prototype errors in the firebug
> console. None of them cause crashes etc, but I thought this would be
> benign?
>
> Any information is appreciated on any of these points.
>
> Best Regards,
> Rick


First of all, why are your ajax requests taking longer than 5 seconds?

Second, asynchronous means that javascript and user interaction will
continue to take place while the request is being fetched.  When the
timer clicks off again, the new request has no way of knowing the status
of the old request.a

Third, you can specify a :condition in the options hash, which is a
javascript expression that must return true in order to send the
request.  So I imagine that you could do something like this:

<%=
  periodically_call_remote(
    :url       => { :action => 'foo' },
    :condition => "!waitingForFoo",
    :loading   => 'waitingForFoo = true',
    :complete  => 'waitingForFoo = false'
  )
%>

This should only send the request if you are not waiting for one.
This topic is locked and can not be replied to.