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 (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 -- Posted via http://www.ruby-forum.com/.
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 On 1/17/06, Nate Drake <ndrake@gmail.com> wrote:> 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 > (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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nate Drake
2006-Jan-19 14:22 UTC
[Rails] Re: Newbie question about periodically_call_remote
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:
<html>
<head>
<title>Builder</title>
<%= javascript_include_tag :defaults %>
</head>
<body>
<%= link_to_remote( "click here",
:update => "update",
:url =>{ :action => "build" }) %>
<div id="update">
</div>
<div id="status">
</div>
</body>
</html>
==== _status.rhtml:
<p>
<div>
<%= periodically_call_remote(
:update => "status",
:url => {:action => "printStatus"}) if
session["building"]
== 1 %>
</div>
</p>
--
Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Q: periodically_call_remote ( how to make it execute just once? )
- Pass parameters in periodically_call_remote?
- Can I send a redirect_to() call to a periodically_call_remote() function?...
- Initial load time when periodically_call_remote
- Is there a huge performance difference between using multiple periodically_call_remote functions or one?