Jens-Christian Fischer
2006-Oct-04 14:49 UTC
[Backgroundrb-devel] do_work and long running rails tasks?
Hi there I have some long running queries against a nice litte database (20 million new records per day) that I have offloaded to backgroundRB. The trouble is, that backgroundrb seems to be blockin on Model.find calls. Here''s the code --- worker.rb -- def do_work(args) @rows = [] @percent = 0 @host = Host.find( args[:id]) ips = @host.ipaddresses step = 100.0/ips.size ips.each do |ip| @percent += step new_rows = Sysloglog.find(:all, :limit => 20, :offset => 0, :order => "eventtime DESC", :conditions => [ "assets_ipaddr_id = ?", ip.id ] ) @rows << new_rows.collect { |s| s.id } end self.kill rescue Exception => e @logger.error "Exception: #{e}" @percent = 100 self.kill end -- snip --- --- controller.rb -- def syslog_progress if request.xhr? worker = MiddleMan.get_worker(session[:host_info]) if worker progress_percent = worker.progress render :update do |page| page.call(''progressPercent'', ''progressbar'', progress_percent) @rows = Sysloglog.find( worker.rows) rescue [] page.replace_html ''syslog_rows'', :partial => "analysis/ syslog", :object => @rows if progress_percent >= 100 page.assign ''stop_polling'', true #<< here is the magick! page.hide ''progress'' MiddleMan.delete_worker(session[:host_info]) end end else render :update do |page| end end else redirect_to :action => ''list'' end end -- snip -- An AJAX call to syslog_progress blocks for the time it takes to do the find( :all .... ) (which sort of renders the whole point of the sending this task to the background moot) Is this the way it is? Any other ways of doing this? Thanks Jens-Christian