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

Chris Hall christopher.k.hall at gmail.com
Tue Sep 5 12:09:55 EDT 2006


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


More information about the Backgroundrb-devel mailing list