# Periodically\_call\_remote not updating page

**URL:** <https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969>\
**Category:** Rails\
**Created:** [June 9, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969 "2008-06-09T17:35:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 9, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/1 "2008-06-09T17:35:49Z")

</div>

I’ve got an app where it takes considerable time to process a list of  
requests from a user, and so would like to use periodically\_call\_remote  
to update a page showing how many requests have been processed. The  
relevant page uses javascript to hide the user submission form and  
replace with an animated “please wait” gif whilst the process runs, and  
I’d also like it to display the count of requests processed. Here’s a  
summary of the code:

\<%= periodically\_call\_remote(:update =\> “status”, :url =\> {:action =\>  
“print\_status”}, :frequency =\> 1) -%\>

| ![Please wait image...](https://test.ruby-forum.com/images/load.gif) | Please wait... |
| | 

 |

\<% form\_remote\_tag :url =\> {:action =\> :process}, :loading =\> "Element.hide('hide\_me'); Element.show('spinner'); Element.show('status')", :complete =\> "Element.hide('spinner'); Element.show('hide\_me'); Element.hide('status')", :update =\> "hide\_me" do %\> \<%= submit\_tag("process") %\>  
\<% end %\>

The print\_status action is simple:

def print\_status  
render :text =\> “#{session[:processed]} requests processed.”  
end

session[:processed] is initially set to 0 but 1 is added to it  
session.update run as each request is iterated over.

The result of this is that the page initially displays “0 requests  
processed” in the correct place, but this text disappears after about 30  
seconds. In another minute or so the browser times out and the “please  
wait” message and spinner vanish as well.  
Can anyone point out where I have got it wrong, above? Thanks.

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 9, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/2 "2008-06-09T17:43:52Z")

</div>

On 9 Jun 2008, at 16:35, Milo T. wrote:

> I’ve got an app where it takes considerable time to process a list of  
> requests from a user, and so would like to use  
> periodically\_call\_remote  
> to update a page showing how many requests have been processed. The  
> relevant page uses javascript to hide the user submission form and  
> replace with an animated “please wait” gif whilst the process runs,  
> and  
> I’d also like it to display the count of requests processed. Here’s a  
> summary of the code:

How many mongrels are you running. if the answer is 1 (eg in  
development) then that’s why. Rails won’t process more than 1  
concurrent request per mongrel.

Fred

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 9, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/3 "2008-06-09T17:49:41Z")

</div>

Frederick C. wrote:

> Rails won’t process more than 1  
> concurrent request per mongrel.

That’s it, then.  
Is there any way of running multiple mongrels in development?  
Thanks.

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 10, 2008, 10:14am UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/4 "2008-06-10T10:14:22Z")

</div>

Frederick C. wrote:

> Long running actions  
> aren’t a good idea for that reason (offload to backgroundrb or similar)

It looks like backgroundrb is the answer then.  
All that’s required is for the user to be notified when their data are  
ready for collection and the site already does that by e-mail.  
Thanks!

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 9, 2008, 5:58pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/5 "2008-06-09T17:58:37Z")

</div>

On 9 Jun 2008, at 16:49, Milo T. wrote:

> Frederick C. wrote:
> 
> > Rails won’t process more than 1  
> > concurrent request per mongrel.
> 
> That’s it, then.  
> Is there any way of running multiple mongrels in development?  
> Thanks.

Same way as you would in production 🙂 (mongrel cluster behind  
something (eg apache) proxying to it).  
That won’t solve your problem though: apache etc… will choose the  
mongrel to proxy to round-robin style, so half of your requests will  
be queued up behind this long running action. Long running actions  
aren’t a good idea for that reason (offload to backgroundrb or similar)

Fred

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [June 12, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-not-updating-page/139969/6 "2008-06-12T14:04:23Z")

</div>

Backgroundrb worked nicely for that particular problem, but now another  
has cropped up.  
One particular page allows the user to search through the database to  
find and select some data that will be processed by the really long  
query that backgroundrb deals with. The sequence goes as follows:

1. User starts the search, browser displays animated gif and says  
“please wait.”
2. After two minutes the browser times out and displays a blank page.
3. After three minutes the mysql query finishes and is stored in the  
mysql cache.
4. If the user tries the same query again the cached results appear in  
seconds.

This is a bit of a nuisance. Does anyone have any suggestions for  
dealing with this one?
