class Believer::Command

Attributes

consistency_level[RW]
record_class[RW]

Public Class Methods

new(attrs = {}) click to toggle source
# 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

Public Instance Methods

can_execute?() click to toggle source
# File lib/believer/command.rb, line 48
def can_execute?
  true
end
clone() click to toggle source
# File lib/believer/command.rb, line 30
def clone
  self.class.new(query_attributes)
end
command_name() click to toggle source
# File lib/believer/command.rb, line 44
def command_name
  self.class.name.split('::').last.underscore
end
consistency(level) click to toggle source
# File lib/believer/command.rb, line 34
def consistency(level)
  c = clone
  c.consistency_level = level
  c
end
execute(name = nil) click to toggle source
# File lib/believer/command.rb, line 52
def execute(name = nil)
  return false unless can_execute?

  @record_class.connection_pool.with do |connection|
    cql = to_cql
    begin
      name = "#{record_class.name} #{command_name}" if name.nil?
      return ActiveSupport::Notifications.instrument('cql.believer', :cql => cql, :name => name) do

        #unless consistency_level.nil? || consistency_level.empty?
        #  exec_opts ||= {}
        #  exec_opts[:consistency] = consistency_level
        #end
        exec_opts = execution_options
        begin
          return connection.execute(cql, exec_opts)
        rescue Cql::NotConnectedError => not_connected
          connection.connect
          return connection.execute(cql, exec_opts)
        end
      end
    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(connection)
      raise e
    end
  end

end
execution_options() click to toggle source
# File lib/believer/command.rb, line 13
def execution_options
  @execution_options ||= {}
  exec_global_opts = ::Believer::Base.environment.believer_configuration[:execution]
  unless exec_global_opts.nil?
    @execution_options.merge!(exec_global_opts.symbolize_keys)
  end
  @execution_options
end
execution_options=(opts) click to toggle source
# File lib/believer/command.rb, line 22
def execution_options=(opts)
  execution_options.merge!(opts)
end
override_execution_options(opts = {}) click to toggle source
# File lib/believer/command.rb, line 26
def override_execution_options(opts = {})
  @execution_options = opts
end
query_attributes() click to toggle source
# File lib/believer/command.rb, line 40
def query_attributes
  {:record_class => @record_class, :consistency_level => @consistency_level}
end