# Newbie question about periodically\_call\_remote

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-periodically-call-remote/52699>\
**Category:** Rails\
**Created:** [January 18, 2006, 2:41am UTC](https://www.ruby-forum.com/t/newbie-question-about-periodically-call-remote/52699 "2006-01-18T02:41:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndrake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@ndrake](https://www.ruby-forum.com/u/ndrake)\
**Post date:** [January 18, 2006, 2:41am UTC](https://www.ruby-forum.com/t/newbie-question-about-periodically-call-remote/52699/1 "2006-01-18T02:41:02Z")

</div>

Hi,

I’m new to Ruby on Rails (and Ruby itself). So far, I’ve been able to  
find answers to most of my questions in the docs or mailing lists. One  
thing I haven’t been able to find the answer to is how to stop a  
periodically\_call\_remote call. My first Rails app is going to be a  
front-end for our Ant-based build system at work. While the build is  
running, I’d like to give the user status info. To do this, I’m using a  
scheme I found here:  
[http://rails.techno-weenie.net/question/2005/12/24/how\_do\_you\_display\_the\_progress\_of\_a\_long\_running\_action](http://rails.techno-weenie.net/question/2005/12/24/how_do_you_display_the_progress_of_a_long_running_action)  
(See post 5). The problem is, after the build has completed, I’d like  
to stop the periodically\_call\_remote from executing. What is the best  
way to do this?

Thanks!

Nate

---

<div class="post-metadata">

**Author:** ![ndrake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@ndrake](https://www.ruby-forum.com/u/ndrake)\
**Post date:** [January 18, 2006, 2:48am UTC](https://www.ruby-forum.com/t/newbie-question-about-periodically-call-remote/52699/2 "2006-01-18T02:48:59Z")

</div>

Well, (I think) one way to do it would be to have the  
periodically\_call\_remote call in the HTML fragment that is being  
refreshed. In that fragment, check to see if the build is complete,  
and if so, omit the call to periodically\_call\_remote.

I’m a Rails noob and have not done this myself, but I can’t see any  
reason why this wouldn’t work. Maybe someone with more AJAX  
experience can come up with something better?

-Will

---

<div class="post-metadata">

**Author:** ![ndrake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@ndrake](https://www.ruby-forum.com/u/ndrake)\
**Post date:** [January 19, 2006, 3:59pm UTC](https://www.ruby-forum.com/t/newbie-question-about-periodically-call-remote/52699/3 "2006-01-19T15:59:01Z")

</div>

Thanks for the reply, Will! I’ve also run into another issue. In the  
build method of my controller, I do a IO.popen() to execute ant and  
build our app. Even though I’m using link\_to\_remote to call the build  
action, it seems to block the periodically\_call\_remote I render to the  
client. Should this work or am I going about this whole thing the wrong  
way? Would it be better to use drb and have my build action talk to a  
remote app which actually runs the builds?

Below is the code I have now. Any tips would be greatly appreciated.

Thanks!!

Nate

==== builder\_controller.rb:

def build  
# Session var containing status message to show user  
session[“build\_status”] = “Starting build…”

```
# Session var used to indicate if a build is running
session["building"] = 1

session.update

render :partial => 'status'

IO.popen("cd /tmp && sleep 60") # This will execute ant
Process.wait

if ($? >> 8) == 0 then
  session["build_status"] = "Built ok"
  session.update
else
  session["build_status"] = "Build failed."
  session.update
end

session["building"] = 0
session.update

```

end

def printStatus  
render :text =\> session[“build\_status”]  
end

==== index.rhtml:

 Builder \<%= javascript\_include\_tag :defaults %\>

\<%= link\_to\_remote( “click here”,  
:update =\> “update”,  
:url =\>{ :action =\> “build” }) %\>

==== \_status.rhtml:

 \<%= periodically\_call\_remote( :update =\> "status", :url =\> {:action =\> "printStatus"}) if session["building"] == 1 %\>
