Sha256: 52ab4fc37538b027aa761da785c3550a2610033b7e3d6097a8c8729a51c34c5b

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module Blazer
  class RunStatement
    def perform(statement, options = {})
      query = options[:query]

      data_source = statement.data_source
      statement.bind

      # audit
      if Blazer.audit
        audit_statement = statement.bind_statement
        audit_statement += "\n\n#{statement.bind_values.to_json}" if statement.bind_values.any?
        audit = Blazer::Audit.new(statement: audit_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.variables.any?
        query.checks.each do |check|
          check.update_state(result)
        end
      end

      result
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blazer-2.6.4 lib/blazer/run_statement.rb
blazer-2.6.3 lib/blazer/run_statement.rb
blazer-2.6.2 lib/blazer/run_statement.rb
blazer-2.6.1 lib/blazer/run_statement.rb
blazer-2.6.0 lib/blazer/run_statement.rb