[Backgroundrb-devel] question about passing array of AR objects to worker

Ezra Zygmuntowicz ezmobius at gmail.com
Wed Sep 6 13:30:02 EDT 2006


Hi ~

On Sep 5, 2006, at 9:09 AM, Chris Hall wrote:

> got a wierd problem maybe someone can help with.
>
> whenever i try to pass an array or AR objects to my worker, i end up
> with a DRb object in the worker...here's an example
>
> class SearchWorker < BackgrounDRb::Rails
>
>   attr_reader :resources
>
>   def do_work(resources)
>     logger.info resources.inspect
>   end
> end
>
> class SearchController < ApplicationController
>
>   def start_search
>     @resources = Resource.find(:all)
>     logger.info @resources.inspect
>     session[:job_key] = MiddleMan.new_worker(:class => :search_worker,
> :args => @resources)
>   end
> end
>
> class Resource < ActiveRecord::Base
>   include DRbUndumped
>   # attribute, "uri", string
> end
>
> now, my controller logs the array as:
>
> [#<Resource:0xb79d9f58
> @attributes={"uri"=>"http://www.google.com/search?hl=en&q=ruby+on 
> +rails&btnG=Google+Search",
> "id"=>"1"}>, #<Resource:0xb79d9ee0
> @attributes={"uri"=>"http://eee.tsinghua.edu.cn/", "id"=>"2"}>,
> #<Resource:0xb79d9ea4
> @attributes={"uri"=>"http://www.digg.com/?s=ruby+on+rails",
> "id"=>"3"}>, #<Resource:0xb79d9e68
> @attributes={"uri"=>"http://www.a9.com/ruby%20on%20rails",
> "id"=>"4"}>, #<Resource:0xb79d9e2c
> @attributes={"uri"=>"http://www.yahoo.com/search?p=ruby+on 
> +rails&fr=FP-tab-web-t500&toggle=1&cop=&ei=UTF-8",
> "id"=>"5"}>, #<Resource:0xb79d9da0
> @attributes={"uri"=>"http://search.msn.com/results.aspx?q=ruby+on 
> +rails&FORM=QBHP",
> "id"=>"6"}>]
>
>
> but the worker logs it as (in backgroundrb.log) as
>
> #<DRb::DRbObject:0xb77c09a8 @ref=-607202372, @uri="druby:// 
> localhost:42531">
>
> can someone explain what's going on here?
>
> Chris


Hey Chris-

	This is the way that DRb works. For any object that you include  
DRbUndumped into, drb creates a proxy DRbObject on the other side of  
the wire. So #inspect will tell you its a DRbObject instead of your  
AR model. But you can just pretend that it really is your AR model  
and call whatever methods on it that you want and it will work. Its  
just that #inspect shows th proxy object instead of what the real  
object is.

-Ezra





More information about the Backgroundrb-devel mailing list