Class: Webhookdb::ConnectionCache::Available
- Inherits:
-
Struct
- Object
- Struct
- Webhookdb::ConnectionCache::Available
- Defined in:
- lib/webhookdb/connection_cache.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#validated_connection ⇒ Object
Return
connection
if it has not been idle long enough, or if it has been idle, then validate it (SELECT 1), and returnconnection
if it’s valid, ornil
if the database disconnected it.
Instance Attribute Details
#at ⇒ Object
Returns the value of attribute at
89 90 91 |
# File 'lib/webhookdb/connection_cache.rb', line 89 def at @at end |
#connection ⇒ Object
Returns the value of attribute connection
89 90 91 |
# File 'lib/webhookdb/connection_cache.rb', line 89 def connection @connection end |
Instance Method Details
#validated_connection ⇒ Object
Return connection
if it has not been idle long enough, or if it has been idle, then validate it (SELECT 1), and return connection
if it’s valid, or nil
if the database disconnected it.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/webhookdb/connection_cache.rb', line 95 def validated_connection needs_validation_at = self.at + Webhookdb::ConnectionCache.idle_timeout return self.connection if needs_validation_at > Time.now begin self.connection << "SELECT 1" return self.connection rescue Sequel::DatabaseDisconnectError self.connection.disconnect return nil end end |