beanstalk w/ ruby client gotcha - beware putting non strings

2 views
Skip to first unread message

Rob Sanheim

unread,
Jul 15, 2008, 3:52:12 AM7/15/08
to beanstalk-talk
I just spent at least a half hour trying to figure out why this would
lock mongrel (and webrick):

BEANSTALK.put(id)

Where id was the plain old id from an ActiveRecord model. This fixed
it:

BEANSTALK.put(id.to_s)

So trying to put anything onto the queue that is an integer simply
locked mongrel hard. Apparently I'm spoiled by Rails calling to_s on
anything where it needs it =) Maybe the client should be tweaked to
do this, or maybe raise an ArgumentError to fail fast?

Just thought I would post this gotcha for the next guy who gets stuck
on it.

- Rob

http://robsanheim.com
http://thinkrelevance.com

Dan Mayer

unread,
Jul 15, 2008, 3:54:06 PM7/15/08
to beansta...@googlegroups.com
you can put other object in if you wrap it with the beanstalk yml calls

put:
bean_queue.yput(msg)

take:
job = bean_queue.reserve
body = job.ybody
deleted = job.delete

Which might be good if you are planning on passing much non string data.

peace,
Dan

--
Dan Mayer
Co-founder, Devver
(http://devver.net)
follow us on twitter: http://twitter.com/devver
My Blog (http://mayerdan.com)

Keith Rarick

unread,
Jul 15, 2008, 5:58:55 PM7/15/08
to beansta...@googlegroups.com
On Tue, Jul 15, 2008 at 12:52 AM, Rob Sanheim <rsan...@gmail.com> wrote:
>
> I just spent at least a half hour trying to figure out why this would
> lock mongrel (and webrick):
>
> BEANSTALK.put(id)

Thanks! This is a bug.

The client implicitly called to_s on the object, but incorrectly
called .size on the original object, not the resulting string.
Fixnum#size returns either 4 or 8, depending on your hardware, so
beanstalkd was waiting for more data.

Now fixed in git.

Though, as Dan suggested, you might want to consider using yput and
ybody if you're not just dealing with strings.

kr

Reply all
Reply to author
Forward
0 new messages