Permalink
Browse files

Handle transient beanstalkd connection failure

* Requires on_connect (patch submitted to em-jack)
  • Loading branch information...
1 parent 8225060 commit d7cb850ec331efbc04f4fb8db5980ba348533639 @mloughran committed Sep 9, 2011
Showing with 13 additions and 6 deletions.
  1. +13 −6 lib/juggler/runner.rb
View
@@ -132,7 +132,8 @@ def reserve
def run
@on = true
Runner.start(self)
- reserve_if_necessary
+ # Creates beanstalkd connection - reserve happens on connect
+ connection
end
def stop
@@ -160,11 +161,17 @@ def handle_exception(e, message)
end
def connection
- @connection ||= EMJack::Connection.new({
- :host => Juggler.server.host,
- :port => Juggler.server.port,
- :tube => @queue
- })
+ @connection ||= begin
+ c = EMJack::Connection.new({
+ :host => Juggler.server.host,
+ :port => Juggler.server.port,
+ })
+ c.on_connect {
+ c.watch(@queue)
+ reserve_if_necessary
+ }
+ c
+ end
end
# Iterates over all jobs reserved on this connection and fails them if

0 comments on commit d7cb850

Please sign in to comment.