# 'm having trouble with BackgrounDrb

**URL:** <https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248>\
**Category:** Rails\
**Created:** [July 5, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248 "2006-07-05T22:52:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 5, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/1 "2006-07-05T22:52:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 6, 2006, 5:40am UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/2 "2006-07-06T05:40:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 6, 2006, 11:27am UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/3 "2006-07-06T11:27:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 6, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/4 "2006-07-06T17:27:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 6, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/5 "2006-07-06T18:33:18Z")

</div>

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](http://rubyforge.org/mailman/listinfo/backgroundrb-devel)

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 6, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/m-having-trouble-with-backgroundrb/97248/6 "2006-07-06T19:06:06Z")

</div>

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](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
