# How to show progress

**URL:** <https://www.ruby-forum.com/t/how-to-show-progress/51501>\
**Category:** Rails\
**Created:** [January 1, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501 "2006-01-01T22:07:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 1, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/1 "2006-01-01T22:07:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 2, 2006, 12:39am UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/2 "2006-01-02T00:39:09Z")

</div>

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://segment7.net/projects/ruby/drb/introduction.html)  
[http://ian.blenke.com/drb](http://ian.blenke.com/drb)  
[http://www.chadfowler.com/ruby/drb.html](http://www.chadfowler.com/ruby/drb.html)

```
Hope that helps

```

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 3, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/3 "2006-01-03T16:42:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 4, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/4 "2006-01-04T20:41:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 4, 2006, 11:24pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/5 "2006-01-04T23:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 5, 2006, 12:26am UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/6 "2006-01-05T00:26:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 5, 2006, 12:33am UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/7 "2006-01-05T00:33:23Z")

</div>

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.:

---

<div class="post-metadata">

**Author:** ![Gerry\_Shaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Gerry\_Shaw](https://www.ruby-forum.com/u/Gerry_Shaw)\
**Post date:** [January 5, 2006, 1:06pm UTC](https://www.ruby-forum.com/t/how-to-show-progress/51501/8 "2006-01-05T13:06:48Z")

</div>

Try this:

[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)

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.
