right_support 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,11 +110,10 @@ module RightSupport::Net::Balancing
110
110
  # Selection of the next endpoint using RoundRobin
111
111
  @counter += 1 unless endpoints.size < @last_size
112
112
  @counter = 0 if @counter == endpoints.size
113
- i = @counter % endpoints.size
114
113
  @last_size = endpoints.size
115
114
 
116
115
  # Returns false or true, depending on whether EP is yellow or not
117
- [ endpoints[i][0], endpoints[i][1][:n_level] != 0 ]
116
+ [ endpoints[@counter][0], endpoints[@counter][1][:n_level] != 0 ]
118
117
  end
119
118
 
120
119
  def good(endpoint, t0, t1)
@@ -126,7 +125,20 @@ module RightSupport::Net::Balancing
126
125
  end
127
126
 
128
127
  def health_check(endpoint)
129
- @stack.increase_state(endpoint,t0,Time.now) unless @health_check.call(endpoint)
128
+ t0 = Time.now
129
+ result = @health_check.call(endpoint)
130
+ t1 = Time.now
131
+ if result
132
+ @stack.decrease_state(endpoint, t0, t1)
133
+ return true
134
+ else
135
+ @stack.increase_state(endpoint, t0, t1)
136
+ return false
137
+ end
138
+ rescue Exception => e
139
+ t1 = Time.now
140
+ @stack.increase_state(endpoint, t0, t1)
141
+ raise e
130
142
  end
131
143
 
132
144
  # Proxy to EndpointStack
@@ -39,5 +39,10 @@ module RightSupport::Net::Balancing
39
39
  def bad(endpoint, t0, t1)
40
40
  #no-op; round robin does not care about failures
41
41
  end
42
+
43
+ def health_check(endpoint)
44
+ #no-op; round robin does not perform health checks
45
+ true
46
+ end
42
47
  end
43
48
  end
@@ -137,7 +137,6 @@ module RightSupport::Net
137
137
  n = 0
138
138
 
139
139
  retry_opt = @options[:retry] || DEFAULT_RETRY_PROC
140
- health_check = @options[:health_check]
141
140
 
142
141
  loop do
143
142
  if complete
@@ -145,7 +144,7 @@ module RightSupport::Net
145
144
  else
146
145
  max_n = retry_opt
147
146
  max_n = max_n.call(@endpoints, n) if max_n.respond_to?(:call)
148
- break if (max_n.is_a?(Integer) && n >= max_n) || !(max_n)
147
+ break if (max_n.is_a?(Integer) && n >= max_n) || [nil, false].include?(max_n)
149
148
  end
150
149
 
151
150
  endpoint, need_health_check = @policy.next
@@ -154,12 +153,15 @@ module RightSupport::Net
154
153
  n += 1
155
154
  t0 = Time.now
156
155
 
157
- # HealthCheck goes here
156
+ # Perform health check if necessary. Note that we guard this with a rescue, because the
157
+ # health check may raise an exception and we want to log the exception info if this happens.
158
158
  if need_health_check
159
159
  begin
160
- @policy.health_check(endpoint)
160
+ unless @policy.health_check(endpoint)
161
+ log_error("RequestBalancer: health check failed to #{endpoint} because of non-true return value")
162
+ next
163
+ end
161
164
  rescue Exception => e
162
- @policy.bad(endpoint, t0, Time.now)
163
165
  log_error("RequestBalancer: health check failed to #{endpoint} because of #{e.class.name}: #{e.message}")
164
166
  next
165
167
  end
@@ -173,7 +175,7 @@ module RightSupport::Net
173
175
  complete = true
174
176
  break
175
177
  rescue Exception => e
176
- if to_raise = handle_exception(endpoint, e)
178
+ if to_raise = handle_exception(endpoint, e, t0)
177
179
  raise(to_raise)
178
180
  else
179
181
  @policy.bad(endpoint, t0, Time.now)
@@ -218,7 +220,7 @@ module RightSupport::Net
218
220
 
219
221
  # Decide what to do with an exception. The decision is influenced by the :fatal
220
222
  # option passed to the constructor.
221
- def handle_exception(endpoint, e)
223
+ def handle_exception(endpoint, e, t0)
222
224
  fatal = @options[:fatal] || DEFAULT_FATAL_PROC
223
225
 
224
226
  #The option may be a proc or lambda; call it to get input
@@ -232,7 +234,8 @@ module RightSupport::Net
232
234
  #whether the exception we're handling is an instance of any mentioned exception
233
235
  #class
234
236
  fatal = fatal.any?{ |c| e.is_a?(c) } if fatal.respond_to?(:any?)
235
- msg = "RequestBalancer: rescued #{fatal ? 'fatal' : 'retryable'} #{e.class.name} during request to #{endpoint}: #{e.message}"
237
+ duration = sprintf('%.4f', Time.now - t0)
238
+ msg = "RequestBalancer: rescued #{fatal ? 'fatal' : 'retryable'} #{e.class.name} during request to #{endpoint}: #{e.message} after #{duration} seconds"
236
239
  log_error msg
237
240
  @options[:on_exception].call(fatal, e, endpoint) if @options[:on_exception]
238
241
 
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '1.0.9'
11
- s.date = '2011-10-17'
10
+ s.version = '1.0.11'
11
+ s.date = '2011-10-21'
12
12
 
13
13
  s.authors = ['Tony Spataro']
14
14
  s.email = 'tony@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 9
10
- version: 1.0.9
9
+ - 11
10
+ version: 1.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-17 00:00:00 -07:00
18
+ date: 2011-10-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency