Chris Hall
2006-Sep-05 16:09 UTC
[Backgroundrb-devel] question about passing array of AR objects to worker
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
Michael Siebert
2006-Sep-06 06:25 UTC
[Backgroundrb-devel] question about passing array of AR objects to worker
its not good to pass AR objects to your worker, that has sth to do with DRb itself, dont know exactly what... a way around that is to pass the ids of the object or somthing else to identify the record. 2006/9/5, Chris Hall <christopher.k.hall at gmail.com>:> > 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 > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Michael Siebert <info at siebert-wd.de> www.siebert-wd.de - Gedanken lesen www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060906/b2fe92b9/attachment.html
Ezra Zygmuntowicz
2006-Sep-06 17:30 UTC
[Backgroundrb-devel] question about passing array of AR objects to worker
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? > > ChrisHey 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