[Backgroundrb-devel] Cannot invoke ActiveRecord subclass accessors in DRb worker

Ezra Zygmuntowicz ezmobius at gmail.com
Thu Jun 15 16:57:13 EDT 2006


.
>
> I'm sure you did test workers with ActiveRecord as I imagine it would
> be a pretty common thing to want to do.
>
> Perhaps it's something with the underlying software then? I'm not
> sure. The ActiveRecord instances work fine if I invoke them directly
> within a Thread in script/console.
>
> Any insight would be great.
>
> Cheers
>
> Dorian
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>


Hey Dorian-


	I'm not sure what could be the problem. I just made a test worker  
that creates, reads and writes ActiveRecords in one worker in a loop  
and ran 10 of them at once and it worked for me. Here is the worker:

class TestWorker < BackgrounDRb::Rails

   def do_work(args)
     10.times do |i|
       post = Post.create :title => "New: #{args[:id]}:#{i}"
       @logger.debug "#{args[:id]} : #{self.object_id}: " + (post.title)
       post = Post.find(args[:id])
       post.title = "New title from worker #{args[:id]}: time: #{i}"
       post.save
       @logger.debug post.title
     end
   end

end

THen I called them like this:

   def index
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 1}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 2}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 3}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 4}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 5}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 6}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 7}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 8}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 9}
     MiddleMan.new_worker :class => :test_worker, :args => {:id => 10}
   end

	And here is a little except from the log so you can see that it is  
working:

1 : 10643990: New: 1:0
New title from worker 1: time: 0
2 : 10624220: New: 2:0
New title from worker 2: time: 0
1 : 10643990: New: 1:1
3 : 10599690: New: 3:0
2 : 10624220: New: 2:1
New title from worker 1: time: 1
4 : 10574310: New: 4:0
New title from worker 3: time: 0
New title from worker 2: time: 1
1 : 10643990: New: 1:2
5 : 10549280: New: 5:0
New title from worker 4: time: 0
3 : 10599690: New: 3:1
2 : 10624220: New: 2:2
New title from worker 1: time: 2
6 : 11499220: New: 6:0
New title from worker 5: time: 0
4 : 10574310: New: 4:1
7 : 11472730: New: 7:0
New title from worker 3: time: 1
New title from worker 2: time: 2
1 : 10643990: New: 1:3
8 : 11435250: New: 8:0
New title from worker 6: time: 0
5 : 10549280: New: 5:1
New title from worker 4: time: 1
9 : 11396760: New: 9:0
New title from worker 7: time: 0
3 : 10599690: New: 3:2


	I'm not sure what the problem could be in your end. If you want I  
can send you a copy of the sample app I have where this works but I  
think it should be working for you. You have the latest version of  
the plugin? And have you tried stoping and restarting the drb server  
and the webserver? I'd like to help you get this working so let me kn  
ow if you can't get around it.

Cheers-
-Ezra


More information about the Backgroundrb-devel mailing list