How to show progress

I’m looking for ideas on how you would implement a controller/view in
Rails that needs to show the progress of a possibly 2-3 minute
operation.

For example the user wants to generate 100 reports that will take about
3 minutes. I would like to have a page that would indicate that the
operation is taking place as well as showing progress as to how far
along. With basic CGI you could render a line of text after each report
was generated and as the page loaded over a few minutes all the
operations would be completed. The user could cancel the operation by
just stopping the page from being loaded (I think). This feels a bit
hacky and I’m looking for a better design but I’m not too sure of one.

The best I’ve come up with is the job is inserted into a database table
and a seperate cron job ticks every minute looking for jobs in that
table that actually runs the job. After the job is submitted the user
is redirected to a job status page which reads the status from the
database. For long operations this makes sense but for 3 minute
operations the user is forced to wait ~30 seconds just for the cron job
to tick, not to mention the site gets pinged every minute even when jobs
might only exist every few days.

How would you design this system? Jobs will take 30 - 300 seconds and
be run a few times every hour. User feedback on progress is important.

On Jan 1, 2006, at 1:07 PM, Gerry Shaw wrote:

was generated and as the page loaded over a few minutes all the
operations the user is forced to wait ~30 seconds just for the cron
job
to tick, not to mention the site gets pinged every minute even when
jobs
might only exist every few days.

How would you design this system? Jobs will take 30 - 300 seconds and
be run a few times every hour. User feedback on progress is
important.

For something like this you might be better off looking at a drb

solution. You could have a simple drb server running that would
process the jobs when your user clicks go. This way you divorce the
long running task from the request-response cycle where it could time
out or have other problems. Then you have your drb server publish a
variable with the status of the long running job. And your user would
have see a web page with a process indicator that gets the status
from the drb server through an ajax request to your rails app. Once
your ajax requests return the finished flag from the drb server you
can redirect the user to a new page with the results.

You can have your web page do a periodically_call_remote to get the

status every 5 or 10 seconds so the user sees the progress. Here are
a few drb tutorial links:

http://segment7.net/projects/ruby/drb/introduction.html
http://ian.blenke.com/drb
http://www.chadfowler.com/ruby/drb.html

Hope that helps

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732

Gerry Shaw wrote:

I’m looking for ideas on how you would implement a controller/view in
Rails that needs to show the progress of a possibly 2-3 minute
operation.

Gerry-

Have you found a solution to this? I’m looking for the same thing.

I considered tearing apart the “upload_progress” thing but it seems that
only works on certain server versions. I was wondering if there is
maybe a simpler method available for folks like us that don’t need to
send status in the middle of an operation.

What I would like is something like:

def do_operation
render_progress(‘Working on step 1…’)
… do step 1 …
render_progress(‘Working on step 2…’)
… do step 2 …
render_progress(‘Working on step 3…’)
… do step 3 …
render_progress(‘Complete!’)
end

Jake

On a related note for this – I am getting the “Application Error: Rails
could not start” when I start an operation that takes a little while
(>30sec). It seems that with the response timing out, the server spits
out an error.

The operation -does- complete, however. So it would certainly be useful
to be able to provide feedback to the user as the operation is going.

Any ideas?

Jake

Jake J. wrote:

Gerry Shaw wrote:

I’m looking for ideas on how you would implement a controller/view in
Rails that needs to show the progress of a possibly 2-3 minute
operation.

Gerry-

Have you found a solution to this? I’m looking for the same thing.

I considered tearing apart the “upload_progress” thing but it seems that
only works on certain server versions. I was wondering if there is
maybe a simpler method available for folks like us that don’t need to
send status in the middle of an operation.

What I would like is something like:

def do_operation
render_progress(‘Working on step 1…’)
… do step 1 …
render_progress(‘Working on step 2…’)
… do step 2 …
render_progress(‘Working on step 3…’)
… do step 3 …
render_progress(‘Complete!’)
end

Jake

Jake J. wrote:

Have you found a solution to this? I’m looking for the same thing.

Well I have a solution using cron and the database, I’m just not very
happy with it. I think the drb route is the “right way” to go about it
and did consider it but before I sunk too much time into that path I was
looking for a sanity check from some other developers.

I don’t think you’ll be able to do what you want with rails wrt to the
render a bit, do a bit as rails want to composite the entire page before
sending it to the browser. If there is a way around this then that
would solve both of our problems.

Good luck and share your results if find something useful.

Gerry Shaw wrote:

I don’t think you’ll be able to do what you want with rails wrt to the
render a bit, do a bit as rails want to composite the entire page before
sending it to the browser. If there is a way around this then that
would solve both of our problems.

Good luck and share your results if find something useful.

Gerry-

Have you seen the “upload_progress” addition that some have done? It is
actually included in Rails, but I think it comes with a caveat that it
doesn’t work with all browsers / servers. I read that a modified fcgi
server was required.

I’m not sure what the current state of this is. However, it seems to me
that doing an upload progress bar is actually more difficult to manage
than step-wise progress. I’m going to look into this drb thing.

Originally, I thought this would just be a nice feature. But given that
my app yields an error after about 30 secs, I’m upgrading this to a
necessity.

Jake

Currently form_with_upload_progress works only with apache and fcgi.
Im not sure but i think lighttpd is also supported.

Basti

Am 05.01.2006 um 00:26 schrieb Jake J.:

Try this:

http://rails.techno-weenie.net/question/2005/12/24/how_do_you_display_the_progress_of_a_long_running_action

Gerry Shaw wrote:

I’m looking for ideas on how you would implement a controller/view in
Rails that needs to show the progress of a possibly 2-3 minute
operation.