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 = EMJack::Connection.new
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 :)
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
The
EMJack::Connection
object is a deferrable, however you can't doThis doesn't work because
EMJack::Connection
(which is a deferrable) fails on the first unsuccessful connection attempt. TheConnection#disconnected
method callsset_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 anon_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 anon_connect
callback.Code is attached but not tested - if you're happy with this addition then I'll add the tests for it :)