When processing an action which takes a long period of time, I would like to update the user as to the progress of the transaction. How can I do this in Rails? Since I can only render once in an action, I don''t see how I can send updates. After the end of the process, I am sending the generated file, e.g., def print_report record_list = Record.find (...) # long list of records pdf = PDF::Writer.new for record in record_list # do processing which adds to the PDF ... # ideally update the user periodically with status # (e.g., record x of y or %complete) end send_data(pdf.render, :filename => "report.pdf", :type => "application/pdf") end I tried implementing such an update via AJAX using the remote update function but I couldn''t figure out how to get the record number from the print_report action to the action being called remotely to update the user''s page. Can anyone post an example (or a link to one) or send me an email with an example?
I prefer not to have these long-running transactions take place synchronously. I load up the relevant data into a queue in the database, and a Ruby runner script processes the queue, sleeps for a few seconds, then loops. This way, I don''t tie up my limited and memory intensive cgi processes with user waiting time. When an item is ready, I fire off an email to the user to inform him. In line with this, you could also use periodically_call_remote to poll the queue. The queue processing script periodically writes back to the queue an estimate of the percent finished. If you don''t feel that this is responsive enough, you could have multiple queue processing scripts running at once. If you have 3 running, the first one handles queue rows with id % 3 == 0, the second id % 3 == 1, etc. On 10/11/05, cvoltz <cjunk-cTAGtEdy3/s@public.gmane.org> wrote:> When processing an action which takes a long period of time, I would like to > update the user as to the progress of the transaction. How can I do this in > Rails? Since I can only render once in an action, I don''t see how I can send > updates. After the end of the process, I am sending the generated file, e.g., > > def print_report > record_list = Record.find (...) # long list of records > pdf = PDF::Writer.new > for record in record_list > # do processing which adds to the PDF > ... > # ideally update the user periodically with status > # (e.g., record x of y or %complete) > end > > send_data(pdf.render, :filename => "report.pdf", :type => "application/pdf") > end > > I tried implementing such an update via AJAX using the remote update function > but I couldn''t figure out how to get the record number from the print_report > action to the action being called remotely to update the user''s page. > > Can anyone post an example (or a link to one) or send me an email with an > example? > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Kyle Maxwell wrote:> I prefer not to have these long-running transactions take place > synchronously. I load up the relevant data into a queue in the[snip] Me too.. but.>> def print_report >> record_list = Record.find (...) # long list of records >> pdf = PDF::Writer.new >> for record in record_list >> # do processing which adds to the PDF >> ... >> # ideally update the user periodically with status >> # (e.g., record x of y or %complete) >> end >> >> send_data(pdf.render, :filename => "report.pdf", :type => "application/pdf") >> endYou could create another action called "print_report_status", meant to run in parallel with "print_report", and call it via XHR to dynamically update a status bar in the browser. This requires a JavaScript enabled client, of course. --Steve
Maybe Matching Threads
- [PATCH 8/9] drm: remove no longer needed drm-get-put coccinelle script
- [Bridge] [netfilter][bridge...?][BUG report] vmalloc-out-of-bounds Read in __ebt_unregister_table
- [RFC PATCH] drm/nouveau/fb/ram/gk104: move assignment out of condition
- a good real time network speed meter
- Bandwidth Meter/monitoring