# BackgrounDRb causing freeze and Mongrel timeout

**URL:** <https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860>\
**Category:** Rails\
**Created:** [June 8, 2008, 9:51am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860 "2008-06-08T09:51:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 8, 2008, 9:51am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/1 "2008-06-08T09:51:29Z")

</div>

I just installed BackgrounDRb to take care of sending emails to a list  
of users and when I try to call the worker, it causes the request to  
“freeze” until Mongrel times out.

This is the line that it fails on:

MiddleMan.worker(:invite\_worker).send\_invite\_emails\_test(@event.id,  
send\_to)

The ‘send\_to’ parameter is an array of user type (strings) which the  
worker will use to filter the list to send the email to. If I remove  
this array things work fine. So does this mean I’m limited to  
primitive types when I call a worker function?

Here’s the worker code:

def send\_invite\_emails\_test(event\_id, send\_to)  
logger.debug(“Start message…”)  
event = Event.find(event\_id)

```
for invite in event.invites
  logger.debug("For invite #{invite.id}")
end

```

end

The various log files that BackgrounDRb don’t seem to be much help  
either. If I call ‘logger.debug’ inside a worker, where does the log  
message go?

Any thoughts?

Thanks,  
Jeremy

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 8, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/2 "2008-06-08T17:57:35Z")

</div>

On Sun, Jun 8, 2008 at 1:21 PM, Mozmonkey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> The ‘send\_to’ parameter is an array of user type (strings) which the  
> for invite in event.invites  
> logger.debug(“For invite #{invite.id}”)  
> end  
> end
> 
> The various log files that BackgrounDRb don’t seem to be much help  
> either. If I call ‘logger.debug’ inside a worker, where does the log  
> message go?
> 
> Any thoughts?

I should have told you this earlier, but running git version of  
BackgrounDRb is currently the best way to go.

[http://gnufied.org/2008/05/21/bleeding-edge-version-of-backgroundrb-for-better-memory-usage/](http://gnufied.org/2008/05/21/bleeding-edge-version-of-backgroundrb-for-better-memory-usage/)

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 9, 2008, 1:34am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/3 "2008-06-09T01:34:24Z")

</div>

I upgraded it through Git and it still stalls and times out. Any  
other thoughts?

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 9, 2008, 2:19am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/4 "2008-06-09T02:19:30Z")

</div>

On Sun, 2008-06-08 at 00:51 -0700, Mozmonkey wrote:

> worker will use to filter the list to send the email to. If I remove  
> logger.debug(“For invite #{invite.id}”)  
> end  
> end
> 
> The various log files that BackgrounDRb don’t seem to be much help  
> either. If I call ‘logger.debug’ inside a worker, where does the log  
> message go?
> 
> Any thoughts?

* * *

my setup backgroundrb logs at log/backgroundrb\_11006\_debug.log

I don’t think this is the issue but I typically wouldn’t use a name like  
‘send\_to’ for a variable or a table field just in case of name  
collision.

Do you have packet and chronic gems installed?

Have you seen [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

Craig

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 9, 2008, 6:51am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/5 "2008-06-09T06:51:47Z")

</div>

On Mon, Jun 9, 2008 at 6:19 AM, Mozmonkey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> gems. I’ve also read through their documentation to see if I could  
> figure out what the problem is – haven’t found anything yet. Until I  
> get this worked out I have installed Spawn and it seems to work on my  
> local environment fine. I’m worried how that’ll work in production,  
> so I’d like to get this figured out if possible.

Well, no worker method will accept two arguments in your code snippet  
you are trying exactly the same.  
If you want two arguments, i am afraid, you will have to pass them as an  
array.

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [June 9, 2008, 2:49am UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/6 "2008-06-09T02:49:55Z")

</div>

> Do you have packet and chronic gems installed?
> 
> Have you seenhttp://backgroundrb.rubyforge.org/

Yes, I have been to the main backgroundrb site and followed their  
instructions for installation and installed the packet and chronic  
gems. I’ve also read through their documentation to see if I could  
figure out what the problem is – haven’t found anything yet. Until I  
get this worked out I have installed Spawn and it seems to work on my  
local environment fine. I’m worried how that’ll work in production,  
so I’d like to get this figured out if possible.

---

<div class="post-metadata">

**Author:** ![Mozmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mozmonkey](https://www.ruby-forum.com/u/Mozmonkey)\
**Post date:** [November 14, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/backgroundrb-causing-freeze-and-mongrel-timeout/139860/7 "2008-11-14T13:01:11Z")

</div>

Hemant K. wrote:

> On Mon, Jun 9, 2008 at 6:19 AM, Mozmonkey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > gems. I’ve also read through their documentation to see if I could  
> > figure out what the problem is – haven’t found anything yet. Until I  
> > get this worked out I have installed Spawn and it seems to work on my  
> > local environment fine. I’m worried how that’ll work in production,  
> > so I’d like to get this figured out if possible.
> 
> Well, no worker method will accept two arguments in your code snippet  
> you are trying exactly the same.  
> If you want two arguments, i am afraid, you will have to pass them as an  
> array.

I’m sure this is resolved by now, one way or the other, but i found that  
it’s simpler to pass all your arguments inside a single hash, eg

MiddleMan.worker(:invite\_worker).send\_invite\_emails\_test(:arg =\>  
{:event\_id =\> @event.id, :send\_to =\> send\_to})

Then pull out at the other end just like a normal hash:

def send\_invite\_emails\_test(arg\_hash)  
logger.debug(“Start message…”)  
event = Event.find(arg\_hash[:event\_id])  
…etc  
end

Also, if you send through an active record object (which i know you  
aren’t doing), then it will die silently with no logging output  
anywhere. That’s my experience anyway. Just mentioning for future  
browsers of this thread.

WRT logging, this probably isn’t the smartest answer but the only way i  
could do it was to make a new logger inside the worker: eg from one of  
mine

class LmailWorker \< BackgrounDRb::MetaWorker  
set\_worker\_name :lmail\_worker

@@logger = Logger.new(“log/backgroundrb\_custom.log”)

def ldb(debug\_text)  
@@logger.info “### #{caller[0]}: #{debug\_text}”  
end

def send\_mail(arg\_hash)  
ldb “arg\_hash = #{arg\_hash.inspect}”  
…etc
