Class: Believer::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/believer/command.rb

Direct Known Subclasses

Batch, Insert, ScopedCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
11
# File 'lib/believer/command.rb', line 6

def initialize(attrs = {})
  attrs.each do |name, value|
    send("#{name}=", value)
  end if attrs.present?
  #@instrumenter = ActiveSupport::Notifications.instrumenter
end

Instance Attribute Details

#record_classObject

Returns the value of attribute record_class.



4
5
6
# File 'lib/believer/command.rb', line 4

def record_class
  @record_class
end

Instance Method Details

#cloneObject



13
14
15
# File 'lib/believer/command.rb', line 13

def clone
  self.class.new(query_attributes)
end

#connectionObject



21
22
23
# File 'lib/believer/command.rb', line 21

def connection
  @record_class.connection
end

#execute(name = 'cql.cql_record') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/believer/command.rb', line 25

def execute(name = 'cql.cql_record')
  cql = to_cql
  begin
    start = Time.now
    puts "Executing #{cql}"
    res = connection.execute(cql)
    #Rails.logger.debug "#{name} #{sprintf "%.3f", (Time.now - start)*1000.0} ms: #{cql}"
    return res
  rescue Cql::Protocol::DecodingError => e
    # Decoding errors tend to #$%# up the connection, resulting in no more activity, so a reconnect is performed here.
    # This is a known issue in cql-rb, and will be fixed in version 1.10
    @record_class.reset_connection
    raise e
  end

end

#query_attributesObject



17
18
19
# File 'lib/believer/command.rb', line 17

def query_attributes
  {:record_class => @record_class}
end