Class: Webhookdb::ConnectionCache::Available

Inherits:
Struct
  • Object
show all
Defined in:
lib/webhookdb/connection_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#atObject

Returns the value of attribute at

Returns:

  • (Object)

    the current value of at



89
90
91
# File 'lib/webhookdb/connection_cache.rb', line 89

def at
  @at
end

#connectionObject

Returns the value of attribute connection

Returns:

  • (Object)

    the current value of connection



89
90
91
# File 'lib/webhookdb/connection_cache.rb', line 89

def connection
  @connection
end

Instance Method Details

#validated_connectionObject

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