On Jul 19, 2006, at 2:53 AM, Chris Roos wrote:
> Hi Ezra,
>
> Thanks for the great work on BackgrounDRb. I have come across a
> couple of problems.
>
> 1. I wanted to define a simple class in the worker file to wrap up and
> pass back some data to my controller. It seems that if I create the
> class either inside or outside of my worker class (in the same file)
> it gets wrapper by a DRb::DRbUknown object and therefore cannot be
> accessed from my controller.
>
> class MyWorker < BackgrounDRb::Rails
>
> class MyResult
> attr_reader :result
> def initialize(result)
> @result = result
> end
> end
>
> def do_work()
> end
> def results
> MyResult.new(100)
> end
>
> end
>
> -- my_controller.rb --
>
> def results
> results = MiddleMan.get_worker(session[:job_key]).results
> p results.result
> #=> undefined method `result'' for
#<DRb::DRbUnknown:0x26d15a4>
> end
>
> I got around this by defining the class within the results method and
> returning like that. Really just wondering if this is by design or a
> bug?
>
> 2. When trying to pass a constant (class name in this instance) in the
> args hash I receive the following error.
>
> #=> undefined method `[]'' for
#<DRb::DRbUnknown:0x13382d4>
>
> (druby://localhost:22222)
> /rails_app/vendor/plugins/backgroundrb/backgroundrb.rb:105:in
> `new_worker''
> (druby://localhost:22222)
> /rails_app/vendor/plugins/backgroundrb/backgroundrb.rb:104:in
> `synchronize''
> (druby://localhost:22222)
> /rails_app/vendor/plugins/backgroundrb/backgroundrb.rb:104:in
> `new_worker''
> app/controllers/feed_controller.rb:36:in
`method_calling_drb_worker''
>
> Again, I wonder if this is by design or a bug?
>
> Cheers,
>
> Chris
Hey Chris-
Both of these issues stem from the same problem. When you see
DRbUnknown errors like that it usually means that there is an issue
sending that particular object over the wire. The answer to this is
almost always that you need to include DRbUndumped in your classes
that are causing these errors. And I would move your little class
outside of the worker class but in the same file. SO make it like this:
class MyResult
include DRbUndumped
attr_reader :result
def initialize(result)
@result = result
end
end
class MyWorker < BackgrounDRb::Rails
def do_work()
end
def results
MyResult.new(100)
end
end
Same thing goes for if you are trying to pass a classname or an AR
object in the args hash. You will have to include DRbUndumped in any
classes you want to sedn back and forth. This tells drb that this
class is undumpable. This means it will keep the class on its normal
side of the network and just pass methods and results back and forth>
This happens sometimes when Drb has problems sending the entire class
across the wire without losing some functionality.
-Ezra