advanced_connection 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b6cf3c3a0fdeacc8cde74431cd95e8ee086a785
4
- data.tar.gz: df3db9850e19c1999b0e219ae8a5670b2c803750
3
+ metadata.gz: 5388815e17dd8184ac2da77dd66f12dc8f420c89
4
+ data.tar.gz: 84e79b7bcaa1806c872f25831c0b688843af0bf8
5
5
  SHA512:
6
- metadata.gz: 268715f2553969f63c9c6b54b17b5c3f1a046fb864f9df865185622b416973d3c749433d9bfab4d803b1e6fe7c984152756e8dfdccbaa5b391b09d6f65e9255b
7
- data.tar.gz: b883bc28735538d6f7f095ac362363b357747028cb29c4aeac305c0d8d9aae5550392f715fca0491abb51ae0d4f39f8c6c9592fac44f5b20b135c4e4e064e316
6
+ metadata.gz: f1f7d22818b463df971f7dde6a17b4f19dcd35c5a048b88863684bf9dbe685e99c8c0a8fdbdd5a044681fd951e779ce0ad06df83dc9e84dab8b251906d8e5024
7
+ data.tar.gz: c9a8fe419202cca4bce4d552c921cceb53d0e71b7b7ee861391172068d1c4670280d4bcf09ed69ce50500c3adce1369003ee01d2e22d9d4654701eae5de6adae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advanced_connection (0.5.5)
4
+ advanced_connection (0.5.6)
5
5
  activerecord (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  rails (~> 4.1)
@@ -179,7 +179,7 @@ module AdvancedConnection::ActiveRecordExt
179
179
  total: total,
180
180
  idle: idle,
181
181
  active: active,
182
- available: available,
182
+ available: available
183
183
  )
184
184
  end
185
185
 
@@ -188,14 +188,14 @@ module AdvancedConnection::ActiveRecordExt
188
188
  slots = connection_limit - @connections.size
189
189
  count = slots if slots < count
190
190
 
191
- if slots >= count
192
- idle_info "Warming up #{count} connection#{count > 1 ? 's' : ''}"
193
- synchronize do
194
- count.times {
195
- conn = checkout_new_connection
196
- @available.add conn
197
- }
198
- end
191
+ return unless slots >= count
192
+
193
+ idle_info "Warming up #{count} connection#{count > 1 ? 's' : ''}"
194
+ synchronize do
195
+ count.times {
196
+ conn = checkout_new_connection
197
+ @available.add conn
198
+ }
199
199
  end
200
200
  end
201
201
 
@@ -224,22 +224,22 @@ module AdvancedConnection::ActiveRecordExt
224
224
  idle_conns = idle_connections
225
225
  idle_count = idle_conns.size
226
226
 
227
- if idle_count > max_idle_connections
228
- cull_count = (idle_count - max_idle_connections)
227
+ return unless idle_count > max_idle_connections
229
228
 
230
- culled = 0
231
- idle_conns.each_with_index do |conn, idx|
232
- last_ci = (Time.now - conn.last_checked_in).to_f
233
- if idx < cull_count
234
- culled += remove_connection(conn) ? 1 : 0
235
- idle_info "culled connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
236
- else
237
- idle_info "kept connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
238
- end
239
- end
229
+ cull_count = (idle_count - max_idle_connections)
240
230
 
241
- idle_info "culled %d connections" % culled
231
+ culled = 0
232
+ idle_conns.each_with_index do |conn, idx|
233
+ last_ci = (Time.now - conn.last_checked_in).to_f
234
+ if idx < cull_count
235
+ culled += remove_connection(conn) ? 1 : 0
236
+ idle_info "culled connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
237
+ else
238
+ idle_info "kept connection ##{idx} id##{conn.object_id} - age:#{conn.instance_age} last_checkin:#{last_ci}"
239
+ end
242
240
  end
241
+
242
+ idle_info "culled %d connections" % culled
243
243
  end
244
244
 
245
245
  private
@@ -101,6 +101,13 @@ module AdvancedConnection
101
101
  @config = DEFAULT_CONFIG.deep_dup
102
102
  end
103
103
 
104
+ def can_enable?
105
+ # don't enable if we're running rake tasks, in particular db: or assets: tasks
106
+ return false if $0.include? 'rake'
107
+ return false if ARGV.grep(/^(assets|db):/).any?
108
+ true
109
+ end
110
+
104
111
  def loaded!
105
112
  @loaded = true
106
113
  end
@@ -23,17 +23,19 @@ module AdvancedConnection
23
23
  class Railtie < Rails::Railtie
24
24
  config.advanced_connection = ActiveSupport::OrderedOptions.new
25
25
 
26
- ActiveSupport.on_load(:before_initialize) do
27
- ActiveSupport.on_load(:active_record) do
28
- # load our intitializer ASAP so we can make use of user defined configuration
29
- load Rails.root.join('config', 'initializers', 'advanced_connection.rb')
30
- ActiveRecord::Base.send(:include, AdvancedConnection::ActiveRecordExt)
26
+ if AdvancedConnection.can_enable?
27
+ ActiveSupport.on_load(:before_initialize) do
28
+ ActiveSupport.on_load(:active_record) do
29
+ # load our intitializer ASAP so we can make use of user defined configuration
30
+ load Rails.root.join('config', 'initializers', 'advanced_connection.rb')
31
+ ActiveRecord::Base.send(:include, AdvancedConnection::ActiveRecordExt)
32
+ end
31
33
  end
32
- end
33
34
 
34
- config.after_initialize do
35
- if AdvancedConnection.enable_idle_connection_manager && AdvancedConnection.warmup_connections
36
- ActiveRecord::Base.connection_handler.connection_pool_list.each(&:warmup_connections)
35
+ config.after_initialize do
36
+ if AdvancedConnection.enable_idle_connection_manager && AdvancedConnection.warmup_connections
37
+ ActiveRecord::Base.connection_handler.connection_pool_list.each(&:warmup_connections)
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -22,7 +22,7 @@
22
22
  module AdvancedConnection
23
23
  MAJOR = 0
24
24
  MINOR = 5
25
- PATCH = 5
25
+ PATCH = 6
26
26
 
27
27
  VERSION = "%d.%d.%d" % [ MAJOR, MINOR, PATCH ]
28
28
  GEM_VERSION = Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl P. Corliss