Hi. I thought that BackgrounDrb was the perfect solution for my long
running report production tasks.
But I can’t seem to get anything useful back out of it.
I set up a simple test worker that just does
class TestWorker < BackgrounDRb::Rails
attr_reader :pupil
def do_work(args)
@progress=0
@pupil=Pupil.find(3)
sleep rand*10
@progress=100
end
when I try to access this via
@pupil=MiddleMan.get_worker(session[:job_key]).pupil
once progress hits 100% [I can access progress fine, BTW]
and use this in a view, I get an error referring to @pupil as
#DRb::DRbUnknown:0xb78228a0 rather than an instance of Pupil.
Am I expecting too much of Drb? I really thought that it would be able
to give me back ActiveRecord objects.
Any help most appreciated 
Robert J.
Hi!
On Jul 5, 2006, at 1:52 PM, Robert J. wrote:
def do_work(args)
@pupil=MiddleMan.get_worker(session[:job_key]).pupil
Any help most appreciated 
Robert J.
Hey Robert-
Using ActiveRecord objects over drb just takes a little extra step.
Try adding this line into your Pupil model:
class Pupil < ActiveRecord::Base
include DRbUndumped
rest of code
end
That should get you where you are going. Maybe you can express what
you are trying to do and I can help you find a better solution to do
what you want. You don’t have to use progress if you don’t need it.
Let me know if you have any more questions.
-Ezra
Ezra Z. wrote:
Hi!
On Jul 5, 2006, at 1:52 PM, Robert J. wrote:
def do_work(args)
@pupil=MiddleMan.get_worker(session[:job_key]).pupil
Any help most appreciated 
Robert J.
Hey Robert-
Using ActiveRecord objects over drb just takes a little extra step.
Try adding this line into your Pupil model:
class Pupil < ActiveRecord::Base
include DRbUndumped
rest of code
end
That should get you where you are going. Maybe you can express what
you are trying to do and I can help you find a better solution to do
what you want. You don’t have to use progress if you don’t need it.
Let me know if you have any more questions.
-Ezra
Hi Ezra! Thanks for the help, and a great big thank you for the work
you’re doing on BackgrounDrb 
Your tip makes the test worker work fine - do I need to include
DRbUndumped in every model that I’m going to use individually? I tried
to be smart and put the include into
class ActiveRecord::Base
include DRbUndumped
end
in environment.rb but this didn’t work. Is there a smart way to
automatically include this in every model class?
To answer your question, what I’m trying to do is to gather together a
hefty pile of ActiveRecord objects, with all the associations, in a
background job, so that the browser doesn’t risk timing out. Once all
this stuff is done, I redirect to the output .rhtml file. At this point
it should be quick, because there are no more calls to ActiveRecord
needed. I definitely want a progress bar.
I think I’m there now in theory (!) , but I’d rather wait to see if
there’s a neat way to do what I asked above before I go ahead and stick
the same include into a dozen different files. It seems like a bug
waiting to happen if I have to remember to include DRbUndumped in every
new model.
Cheers,
Robert
Robert J. wrote:
Ezra Z. wrote:
Hi!
On Jul 5, 2006, at 1:52 PM, Robert J. wrote:
def do_work(args)
@pupil=MiddleMan.get_worker(session[:job_key]).pupil
Any help most appreciated 
Robert J.
Hey Robert-
Using ActiveRecord objects over drb just takes a little extra step.
Try adding this line into your Pupil model:
class Pupil < ActiveRecord::Base
include DRbUndumped
rest of code
end
That should get you where you are going. Maybe you can express what
you are trying to do and I can help you find a better solution to do
what you want. You don’t have to use progress if you don’t need it.
Let me know if you have any more questions.
-Ezra
Hi Ezra! Thanks for the help, and a great big thank you for the work
you’re doing on BackgrounDrb 
Your tip makes the test worker work fine - do I need to include
DRbUndumped in every model that I’m going to use individually? I tried
to be smart and put the include into
class ActiveRecord::Base
include DRbUndumped
end
in environment.rb but this didn’t work. Is there a smart way to
automatically include this in every model class?
To answer your question, what I’m trying to do is to gather together a
hefty pile of ActiveRecord objects, with all the associations, in a
background job, so that the browser doesn’t risk timing out. Once all
this stuff is done, I redirect to the output .rhtml file. At this point
it should be quick, because there are no more calls to ActiveRecord
needed. I definitely want a progress bar.
I think I’m there now in theory (!) , but I’d rather wait to see if
there’s a neat way to do what I asked above before I go ahead and stick
the same include into a dozen different files. It seems like a bug
waiting to happen if I have to remember to include DRbUndumped in every
new model.
Cheers,
Robert
Hi. I’ve been thinking some more about this, and trying to get it
working despite what I said about waiting 
I’m getting strange errors when I try to call methods on objects
returned from BDRb. These methods work fine on the same objects if they
are brought up in the controllers. I did put include DRbUndumped into
every model class.
Anyway, I’ve also realised that I should really be doing EVERYTHING in
the background - what I really want back from the worker is the text of
the report, not the objects that I need to render the report. But
ActionController stuff doesn’t seem to be available to me in the worker.
Robert
On Jul 6, 2006, at 8:27 AM, Robert J. wrote:
Robert J.
automatically include this in every model class?
Robert
Anyway, I’ve also realised that I should really be doing EVERYTHING in
the background - what I really want back from the worker is the
text of
the report, not the objects that I need to render the report. But
ActionController stuff doesn’t seem to be available to me in the
worker.
Robert
Robert-
Yeah you don't have ActionController stuff in the drb server because
there is no HTTP request/response. So what you want to do as far as
returning the text will work fine but you will have to deal with
controller stuff in rails. Maybe if you paste your worker class here
I can be of more help.
Also include full error messages when you get them so I can see what
happened. You might also consider joining the mailing list :
http://rubyforge.org/mailman/listinfo/backgroundrb-devel
Cheers-
-Ezra
Ezra Z. wrote:
On Jul 6, 2006, at 8:27 AM, Robert J. wrote:
Robert J.
automatically include this in every model class?
Robert
Anyway, I’ve also realised that I should really be doing EVERYTHING in
the background - what I really want back from the worker is the
text of
the report, not the objects that I need to render the report. But
ActionController stuff doesn’t seem to be available to me in the
worker.
Robert
Robert-
Yeah you don’t have ActionController stuff in the drb server because
there is no HTTP request/response. So what you want to do as far as
returning the text will work fine but you will have to deal with
controller stuff in rails. Maybe if you paste your worker class here
I can be of more help.
Also include full error messages when you get them so I can see what
happened. You might also consider joining the mailing list :
http://rubyforge.org/mailman/listinfo/backgroundrb-devel
Cheers-
-Ezra
Thanks Ezra. I’m off to a glacier in the Alps to Snowboard for a week -
I’ll bring this up again on the backgroundrb-devel list when I get back.
Cheers,
Robert