elastic_record 0.6.4 → 0.6.5

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'elastic_record'
5
- s.version = '0.6.4'
5
+ s.version = '0.6.5'
6
6
  s.summary = 'Use Elastic Search with your objects'
7
7
  s.description = 'Find your records with elastic search'
8
8
 
@@ -7,6 +7,7 @@ module ElasticRecord
7
7
  # :auto_discovery: false
8
8
 
9
9
  attr_accessor :servers, :options
10
+ attr_accessor :request_count, :current_server
10
11
  def initialize(servers, options = {})
11
12
  if servers.is_a?(Array)
12
13
  self.servers = servers
@@ -14,6 +15,8 @@ module ElasticRecord
14
15
  self.servers = servers.split(',')
15
16
  end
16
17
 
18
+ self.current_server = choose_server
19
+ self.request_count = 0
17
20
  self.options = options
18
21
  end
19
22
 
@@ -72,7 +75,14 @@ module ElasticRecord
72
75
  end
73
76
 
74
77
  def http
75
- host, port = choose_server.split ':'
78
+ self.request_count += 1
79
+
80
+ if request_count > 100
81
+ self.current_server = choose_server
82
+ self.request_count = 0
83
+ end
84
+
85
+ host, port = current_server.split ':'
76
86
 
77
87
  http = Net::HTTP.new(host, port)
78
88
  if options[:timeout]
@@ -2,7 +2,7 @@ module ElasticRecord
2
2
  class LogSubscriber < ActiveSupport::LogSubscriber
3
3
  def request(event)
4
4
  response = event.payload[:response]
5
- info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]} (%.1fms)" % [event.duration]
5
+ debug "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]} (%.1fms)" % [event.duration]
6
6
  # info "--> %d %s %d (%.1fms)" % [response.code, response.message, response.body.to_s.length, event.duration]
7
7
  end
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-15 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arelastic