diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-09-27 18:09:28 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-09-27 19:02:21 -0700 |
commit | aa83722ab57fe05ac88164cfac949bb13c4aa7a5 (patch) | |
tree | 671a0141557e2682014851ed0527b2bf6c9bab06 /lib/unicorn.rb | |
parent | 7774d770f0021e25a644e85ad404e8acb7b81afc (diff) | |
download | unicorn-aa83722ab57fe05ac88164cfac949bb13c4aa7a5.tar.gz |
This allows per-worker listeners to be configured to retry and and not continue until the equivalent worker belonging to a previous master (or even another server) has released the socket. In the Configurator RDoc, include better examples for per-worker server.listen calls using these :tries == -1. Inspired by an example by Chris Wanstrath.
Diffstat (limited to 'lib/unicorn.rb')
-rw-r--r-- | lib/unicorn.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 0e46261..bc5ba23 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -175,10 +175,17 @@ module Unicorn # add a given address to the +listeners+ set, idempotently # Allows workers to add a private, per-process listener via the # after_fork hook. Very useful for debugging and testing. + # +:tries+ may be specified as an option for the number of times + # to retry, and +:delay+ may be specified as the time in seconds + # to delay between retries. + # A negative value for +:tries+ indicates the listen will be + # retried indefinitely, this is useful when workers belonging to + # different masters are spawned during a transparent upgrade. def listen(address, opt = {}.merge(listener_opts[address] || {})) return if String === address && listener_names.include?(address) - delay, tries = 0.5, 5 + delay = opt[:delay] || 0.5 + tries = opt[:tries] || 5 begin io = bind_listen(address, opt) unless TCPServer === io || UNIXServer === io @@ -192,7 +199,8 @@ module Unicorn logger.error "adding listener failed addr=#{address} (in use)" raise err if tries == 0 tries -= 1 - logger.error "retrying in #{delay} seconds (#{tries} tries left)" + logger.error "retrying in #{delay} seconds " \ + "(#{tries < 0 ? 'infinite' : tries} tries left)" sleep(delay) retry end |