[Backgroundrb-devel] Upgrading to 2.0

hemant gethemant at gmail.com
Sun Jan 20 17:14:25 EST 2008


Hi Dale,

On Jan 21, 2008 3:20 AM, Dale Cook <dale at dalecook.us> wrote:
> Thanks for the reply. It seems that there's certainly a fundamental
> difference between our version and 2.0 - I think this has been causing our
> confusion.
>
> None of this is a show stopper for us, but let me see if I've got this
> straight, let's say we had a worker that took a fairly long running task
> (lets say it pulls down csv data from another server and processes it) and
> was capable of updating a number of attributes so that we could report back
> to the user that status and progress. Would it look something like this?
>
> The worker code:
>
> class CsvWorker < BackgrounDRb::MetaWorker
>
>   set_worker_name :csv_worker
>
>   def create(args = nil)
>     @worker_attributes = {:status => 0, total => 0, :progress => 0}
>
>     register_status(@worker_status)
>   end
>
>   def process_file(args = nil)
>
>     #these values are necessary to login to the external csv server
>     login = args[:login]
>     password = args[:password]
>     server_location = args[:server]
>
>     @worker_attributes[:total] = 0
>      @worker_attributes[:progress] = 0
>      @worker_attributes[:status] = "contacting server"
>      register_status(@worker_attributes)
>
>     # not shown here: login to the server, download the file, load the lines
> of the csv file into an array, etc....
>
>     @worker_attributes[:total] = csv_array.length
>     @worker_attributes[:status] = "processing"
>     register_status(@worker_attributes)
>
>     for record in csv_array
>
>       #process the record, or whatever....
>
>        @worker_attributes[:progress] += 1
>
>        register_status(@worker_attributes)
>
>     end
>
>  end
>
> end
>
> Then our controller code would look something like:
>
> class ProcessesController < ApplicationController
>
>   def import
>
>     #generate_job_key generates a new random key for us
>     @job_key = generate_job_key
>
>     MiddleMan.new_worker(:worker => :csv_worker, :job_key => @job_key)
>
>     MiddleMan.ask_work(:worker => :csv_worker, :job_key => @job_key,
> :worker_method => :process_file, :data => {:login => "mylogin", :password =>
> "mypassword", :server => " 192.168.22.55"})
>
>     #send an Ajax.Request function back tot he page to make it access the
> status method
>     render :update do |page|
>
>       page << remote_function(:url => {:action => :status, :controller =>
> "processes", :id => @job_key})
>
>     end
>
>   end
>
>   def status
>
>     results = MiddleMan.ask_status(:worker => :csv_worker, :job_key =
> params[:id])
>
>     #update the page with relevent progress information
>     render :update do |page|
>
>       if(results[:status] = "processing" )
>
>         page['report-progress'].replace_html "#{results[:progress]} records
> processed out of a total of #{results[:total]"
>
>         page << remote_function(:url => {:action => :status, :controller =>
> "processes", :id => params[:id]})
>
>       else
>
>         page['report-progress'].replace_html results[:status]
>
>       end
>
>     end
>
>   end
>
> end
>
> I won't include the actual view since it's just a simple page with a "start"
> link and a div that provides the update information.
>
> We've already tried something like this (actually this is a simplification
> of the test code we're using) but we still haven't had much success -
> perhaps there's simply something wrong here.
>
> Anyway, I also wanted to say thanks to everyone who's worked on
> BackgrounDRb, even if the new version doesn't work out for us (I suspect it
> will) it's an amazing project and we're really thankful that people have
> taken the time and energy to develop it.
>

Yes your code looks alright, at least the part thats dealing with
BackgrounDRb. So whats the error you are getting? If you tell us about
the problem, we can surely straighten it out. Which part is not
working? Do you have errors in RAILS_ROOT/log/backgroundrb_debug.log ?
You can turn log messages in foreground and find out where its failing
and stuff like that.


More information about the Backgroundrb-devel mailing list