with_connection 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class FiberedMonitor
4
+ class LogSubscriber < ActiveSupport::LogSubscriber
5
+ def wait(event)
6
+ return unless logger && logger.debug?
7
+ logger.debug "waited " + (" (%.1fms)" % event.duration) + " for a #{event.payload[:resource]}"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ ActiveRecord::ConnectionAdapters::FiberedMonitor::LogSubscriber.attach_to :connection_pool
@@ -17,15 +17,17 @@ module ActiveRecord
17
17
  end
18
18
 
19
19
  def wait(timeout)
20
- t = timeout || 5
21
- fiber = Fiber.current
22
- x = EM::Timer.new(t) do
23
- @queue.delete(fiber)
24
- fiber.resume(false)
25
- end
26
- @queue << fiber
27
- Fiber.yield.tap do
28
- x.cancel
20
+ ActiveSupport::Notifications.instrument("wait.connection_pool", :resource => self.name) do |payload|
21
+ t = timeout || 5
22
+ fiber = Fiber.current
23
+ x = EM::Timer.new(t) do
24
+ @queue.delete(fiber)
25
+ fiber.resume(false)
26
+ end
27
+ @queue << fiber
28
+ Fiber.yield.tap do
29
+ x.cancel
30
+ end
29
31
  end
30
32
  end
31
33
 
@@ -5,8 +5,8 @@ module WithConnection
5
5
  attr_reader :name
6
6
 
7
7
  def initialize(name, spec)
8
- super spec
9
8
  @name = name
9
+ super spec
10
10
  @disable_warning = !! spec.config[:disable_warning]
11
11
  @debug_with_connection = !! spec.config[:debug_with_connection]
12
12
  ConnectionManagement.connection_pools << self
@@ -26,7 +26,12 @@ module WithConnection
26
26
  if @debug_with_connection && ! @using_with_connection
27
27
  Rails.logger.warn "#{name} not using with_connection, backtrace: #{caller.inspect}"
28
28
  end
29
- checkout_without_debug
29
+
30
+ begin
31
+ checkout_without_debug
32
+ rescue ActiveRecord::ConnectionTimeoutError => e
33
+ raise ActiveRecord::ConnectionTimeoutError, "could not obtain a #{name} connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
34
+ end
30
35
  end
31
36
  alias_method_chain :checkout, :debug
32
37
 
@@ -35,32 +40,6 @@ module WithConnection
35
40
  release_connection
36
41
  end
37
42
 
38
- # copied directly from the ActiveRecord just so I could change the error message
39
- def checkout
40
- # Checkout an available connection
41
- @connection_mutex.synchronize do
42
- loop do
43
- conn = if @checked_out.size < @connections.size
44
- checkout_existing_connection
45
- elsif @connections.size < @size
46
- checkout_new_connection
47
- end
48
- return conn if conn
49
-
50
- @queue.wait(@timeout)
51
-
52
- if(@checked_out.size < @connections.size)
53
- next
54
- else
55
- clear_stale_cached_connections!
56
- if @size == @checked_out.size
57
- raise ActiveRecord::ConnectionTimeoutError, "could not obtain a #{name} connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
58
- end
59
- end
60
-
61
- end
62
- end
63
- end
64
43
 
65
44
  private
66
45
  def new_connection
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "with_connection"
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Youch"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/active_record/fiber_patches.rb",
29
+ "lib/active_record/fiber_patches/log_subscriber.rb",
29
30
  "lib/active_support/cache/features/adapter_methods.rb",
30
31
  "lib/active_support/cache/memcache_connection_pool.rb",
31
32
  "lib/with_connection.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -92,6 +92,7 @@ files:
92
92
  - Rakefile
93
93
  - VERSION
94
94
  - lib/active_record/fiber_patches.rb
95
+ - lib/active_record/fiber_patches/log_subscriber.rb
95
96
  - lib/active_support/cache/features/adapter_methods.rb
96
97
  - lib/active_support/cache/memcache_connection_pool.rb
97
98
  - lib/with_connection.rb
@@ -112,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  segments:
114
115
  - 0
115
- hash: 1872296297786812773
116
+ hash: 2081270842344130397
116
117
  required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  none: false
118
119
  requirements: