Class: Cassanity::Cql::ReconnectableDriver

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cassanity/cql/reconnectable_driver.rb

Overview

Internal: An intermediate driver for cql-rb that supports reconnecting by recycling the underlying Cql::Client instance.

Reconnecting is important when using a forking web server like unicorn, but cql-rb does not allow a Cql::Client instances that has been disconnected to be reconnected.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cql_options = {}) ⇒ ReconnectableDriver

cql_options: Options for constructing a Cql::Client



20
21
22
# File 'lib/cassanity/cql/reconnectable_driver.rb', line 20

def initialize(cql_options = {})
  @cql_options = cql_options
end

Class Method Details

.connect(cql_options = {}) ⇒ Object



15
16
17
# File 'lib/cassanity/cql/reconnectable_driver.rb', line 15

def self.connect(cql_options = {})
  new(cql_options).tap(&:connect)
end

Instance Method Details

#connectObject



24
25
26
27
# File 'lib/cassanity/cql/reconnectable_driver.rb', line 24

def connect
  disconnect
  @driver = ::Cql::Client.connect(@cql_options)
end

#disconnectObject



29
30
31
# File 'lib/cassanity/cql/reconnectable_driver.rb', line 29

def disconnect
  @driver.close if @driver
end