Permalink
Browse files

Fix reconnect success rate to report as percentage. References #428.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3024 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 090bfce commit 9a2de028dc68525bead48a2c9d6aca21b0dc328a @jeremy jeremy committed Nov 14, 2005
Showing with 5 additions and 5 deletions.
  1. +5 −5 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
View
10 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -25,7 +25,7 @@ class AbstractAdapter
@@reconnect_success = 0
@@reconnect_failure = 0
def self.reconnect_success_rate
- @@reconnect_success.to_f / (@@reconnect_success + @@reconnect_failure)
+ (100.0 * @@reconnect_success / (@@reconnect_success + @@reconnect_failure)).to_i
end
def initialize(connection, logger = nil) #:nodoc:
@@ -38,7 +38,7 @@ def initialize(connection, logger = nil) #:nodoc:
def adapter_name
'Abstract'
end
-
+
# Does this adapter support migrations? Backend specific, as the
# abstract adapter always returns +false+.
def supports_migrations?
@@ -50,7 +50,7 @@ def reset_runtime #:nodoc:
rt
end
- protected
+ protected
def log(sql, name)
if block_given?
if @logger and @logger.level <= Logger::INFO
@@ -110,11 +110,11 @@ def reconnect_if_inactive!
reconnect! unless active?
if active?
@@reconnect_success += 1
- @logger.info "#{adapter_name} automatically reconnected. Success rate: #{'%.2f' % self.class.reconnect_success_rate}%" if @logger
+ @logger.info "#{adapter_name} automatically reconnected. Success rate: #{self.class.reconnect_success_rate}%" if @logger
true
else
@@reconnect_failure += 1
- @logger.warn "#{adapter_name} automatic reconnection failed. Success rate: #{'%.2f' % self.class.reconnect_success_rate}%" if @logger
+ @logger.warn "#{adapter_name} automatic reconnection failed. Success rate: #{self.class.reconnect_success_rate}%" if @logger
false
end
else

0 comments on commit 9a2de02

Please sign in to comment.