[Rails] How to show progress

Gerry Shaw gerry_shaw at yahoo.com
Sun Jan 1 21:07:16 GMT 2006


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.

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list