Business intelligence made simple
Namespaced RunStatement correctly
Andrew Kane4749e7c037e7
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 699b21fc..c611e0e0 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -116,7 +116,7 @@ module Blazerend@result = result.firstelse- @result = RunStatement.new.perform(@data_source, @statement, options)+ @result = Blazer::RunStatement.new.perform(@data_source, @statement, options)endif @resultdiff --git a/lib/blazer/run_statement.rb b/lib/blazer/run_statement.rbindex f7363fd4..dc97efeb 100644--- a/lib/blazer/run_statement.rb+++ b/lib/blazer/run_statement.rb@@ -1,38 +1,40 @@-class RunStatement- def perform(data_source, statement, options = {})- query = options[:query]- Blazer.transform_statement.call(data_source, statement) if Blazer.transform_statement+module Blazer+ 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+ # 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+ 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=)+ 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- audit.save! if audit.changed?- end- if query && !result.timed_out?- query.checks.each do |check|- check.update_state(result)+ if query && !result.timed_out?+ query.checks.each do |check|+ check.update_state(result)+ endend- end- result+ result+ endendenddiff --git a/lib/blazer/run_statement_job.rb b/lib/blazer/run_statement_job.rbindex 15d50c16..04ce14f0 100644--- a/lib/blazer/run_statement_job.rb+++ b/lib/blazer/run_statement_job.rb@@ -8,7 +8,7 @@ module Blazerdef perform(result, data_source, statement, options)beginActiveRecord::Base.connection_pool.with_connection do- result << RunStatement.new.perform(data_source, statement, options)+ result << Blazer::RunStatement.new.perform(data_source, statement, options)endrescue Exception => eresult.clear