aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 8187112b64..a52d7f4fb0 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -21,10 +21,11 @@ module ActiveRecord
class AbstractAdapter
include Quoting, DatabaseStatements, SchemaStatements
@@row_even = true
-
+
def initialize(connection, logger = nil) #:nodoc:
@connection, @logger = connection, logger
@runtime = 0
+ @last_verification = 0
end
# Returns the human-readable name of the adapter. Use mixed case - one
@@ -76,6 +77,15 @@ module ActiveRecord
@active = false
end
+ # Lazily verify this connection, calling +active?+ only if it hasn't
+ # been called for +timeout+ seconds.
+ def verify!(timeout)
+ now = Time.now.to_i
+ if (now - @last_verification) > timeout
+ reconnect! unless active?
+ @last_verification = now
+ end
+ end
protected
def log(sql, name)
@@ -95,6 +105,9 @@ module ActiveRecord
end
rescue Exception => e
# Log message and raise exception.
+ # Set last_verfication to 0, so that connection gets verified
+ # upon reentering the request loop
+ @last_verification = 0
message = "#{e.class.name}: #{e.message}: #{sql}"
log_info(message, name, 0)
raise ActiveRecord::StatementInvalid, message