Sha256: b83d19f305444fdcf00bd5fe62119db58c19c637581a072f9aae8234eac45a18

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

class RunStatement
  def perform(data_source, statement, options = {})
    query = options[:query]
    Blazer.transform_statement.call(data_source, statement) if Blazer.transform_statement

    # audit
    if Blazer.audit
      audit = Blazer::Audit.new(statement: statement)
      audit.query = query
      audit.data_source = data_source.id
      audit.user = options[:user]
      audit.save!
    end

    start_time = Time.now
    result = data_source.run_statement(statement, options)
    duration = Time.now - start_time

    if Blazer.audit
      audit.duration = duration if audit.respond_to?(:duration=)
      audit.error = result.error if audit.respond_to?(:error=)
      audit.timed_out = result.timed_out? if audit.respond_to?(:timed_out=)
      audit.cached = result.cached? if audit.respond_to?(:cached=)
      if !result.cached? && duration >= 10
        audit.cost = data_source.cost(statement) if audit.respond_to?(:cost=)
      end
      audit.save! if audit.changed?
    end

    if query && !result.timed_out?
      query.checks.each do |check|
        check.update_state(result)
      end
    end

    result
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blazer-1.6.2 lib/blazer/run_statement.rb
blazer-1.6.1 lib/blazer/run_statement.rb
blazer-1.6.0 lib/blazer/run_statement.rb