Maximilian Schöfmann
2006-Jul-07 17:52 UTC
[Backgroundrb-devel] Problems with ActiveRecord in workers
Hi *, are there some special settings except of "load_rails: true" to make ActiveRecord models accessible within my workers? I''ve just installed the latest version of this great plugin, but I keep getting undefined method [] for #<DRb::DRbUnknown:0x12345> (line 105 in backgroundrb.rb) when one of the arguments for the worker is an ActiveRecord object. I assume that the MiddleMan somehow doesn''t see my models. I have already tried to put model :blabla, :foo, :bar in application.rb, but this didn''t help. Any ideas? Regards, Max
Ezra Zygmuntowicz
2006-Jul-07 18:00 UTC
[Backgroundrb-devel] Problems with ActiveRecord in workers
On Jul 7, 2006, at 10:52 AM, Maximilian Sch?fmann wrote:> Hi *, > > are there some special settings except of "load_rails: true" to make > ActiveRecord models accessible within my workers? > I''ve just installed the latest version of this great plugin, but I > keep > getting > > undefined method [] for #<DRb::DRbUnknown:0x12345> (line 105 in > backgroundrb.rb) > > when one of the arguments for the worker is an ActiveRecord object. > I assume that the MiddleMan somehow doesn''t see my models. I have > already tried to put > > model :blabla, :foo, :bar > > in application.rb, but this didn''t help. > > Any ideas? > > Regards, > MaxHey Max- If you need to pass an active record object to one of your workers as an argument then you need to add one line of code to each model that you intend on using this way. So if the model you want to send from rails to the drb server is Post then you need to add this line: class Post < ActiveRecord::base include DRbUndumped #the rewst of your code end If you add that to the models you need to send to the drb server it will work. Cheers- -Ezra
Maximilian Schöfmann
2006-Jul-07 18:34 UTC
[Backgroundrb-devel] Problems with ActiveRecord in workers
Hi Ezra, thank a lot for the fast answer! I think this plugin is one of the most useful around.> If you need to pass an active record object to one of your workers > as an argument then you need to add one line of code to each model > that you intend on using this way. So if the model you want to send > from rails to the drb server is Post then you need to add this line: > > class Post < ActiveRecord::base > > include DRbUndumpedIf my understanding of DRb is correct, this will stop me from storing these objects in a session... As a workaround, I will try to store them with BackgroundDRb instead of the session. Thanks again, Max
Ezra Zygmuntowicz
2006-Jul-07 18:54 UTC
[Backgroundrb-devel] Problems with ActiveRecord in workers
On Jul 7, 2006, at 11:34 AM, Maximilian Sch?fmann wrote:> Hi Ezra, > > thank a lot for the fast answer! > I think this plugin is one of the most useful around. >> If you need to pass an active record object to one of your >> workers >> as an argument then you need to add one line of code to each model >> that you intend on using this way. So if the model you want to send >> from rails to the drb server is Post then you need to add this line: >> >> class Post < ActiveRecord::base >> >> include DRbUndumped > > If my understanding of DRb is correct, this will stop me from storing > these objects in a session... > As a workaround, I will try to store them with BackgroundDRb > instead of > the session. > > Thanks again, > > MaxMax- I''m not so sure it would keep you from storing models in the session. You should experiment before you give up on that. BUt I don''t like storing whole models in the session. I avoid it by just storing the id of a model in the session and using a before fiulter to repopulate the model from its id on each requests. Believe it or not this is usually faster then unmarshaling an object out of the session. Also what are you doing that requires you to send full AR objects to the drb server as args? Couldn''t you just as easily send the id of the record or a name and then do a find in the drb server instead of sending a full AR object as an arg? Thanks for the kind words. I''m glad you find the plugin useful. I use it all the time now ;) Cheers- -Ezra
Maximilian Schöfmann
2006-Jul-08 08:33 UTC
[Backgroundrb-devel] Problems with ActiveRecord in workers
Hi Ezra, storing them in the session indeed doesn''t work (I tried just PStore, but I think others will use Marshall, too). Marshalling them using YAML would maybe work.> Believe it or not this is usually faster then unmarshaling an > object out of the session. >I didn''t consider that until now, because i thought fetching them from the db would be slower than unmarshalling. This would of course be an option for me. I will give it a try. Thanks for your suggestions Cheers, Max