Not possible to reserve on connected reliably #9

merged 2 commits into from Sep 10, 2011

2 participants


I wanted to reserve after the beanstalkd connection has connected successfully - however this was surprisingly hard to achieve (unless I've just missed something)

Explicitly, this is what I wanted

  • Start queue consumer
  • Wait for at least 1 connection attempt to fail
  • Start beanstalkd
  • Queue consumer should connect and reserve on the queue

The EMJack::Connection object is a deferrable, however you can't do

# Doesn't work
conn =

conn.callback {
  # reserve on tube

This doesn't work because EMJack::Connection (which is a deferrable) fails on the first unsuccessful connection attempt. The Connection#disconnected method calls set_deferred_status(nil) which will clear all callbacks.

My conclusion is that the EMJack::Connection deferrable is used heavily for internal callbacks and thus it's behaviour can't be changed. Therefore an on_connect callback is required.

It's also necessary to have a connected? boolean: in the case that code needs to reserve dynamically, it needs to know whether to just reserve of reserve in an on_connect callback.

Code is attached but not tested - if you're happy with this addition then I'll add the tests for it :)

@dj2 dj2 merged commit ecd85bf into igrigorik:master Sep 10, 2011

This looks good to me. I've merged this part in, if you have time to write some tests please send them my way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment