Business intelligence made simple
Use monotonic time
Andrew Kaned1f61c4be664
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0b0e22b1..4cbb5dce 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,3 +1,7 @@+## 2.6.5 (unreleased)++- Use monotonic time+## 2.6.4 (2022-05-24)- Fixed error with cachingdiff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 15c63894..0a16795d 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -134,11 +134,11 @@ module Blazeroptions = {user: blazer_user, query: @query, refresh_cache: params[:check], run_id: @run_id, async: Blazer.async}if Blazer.async && request.format.symbol != :csvBlazer::RunStatementJob.perform_later(@data_source.id, @statement.statement, options.merge(values: @statement.values))- wait_start = Time.now+ wait_start = Blazer.monotonic_timeloop dosleep(0.1)@result = @data_source.run_results(@run_id)- break if @result || Time.now - wait_start > 3+ break if @result || Blazer.monotonic_time - wait_start > 3endelse@result = Blazer::RunStatement.new.perform(@statement, options)diff --git a/lib/blazer.rb b/lib/blazer.rbindex 3c6eaf90..0fe03894 100644--- a/lib/blazer.rb+++ b/lib/blazer.rb@@ -257,6 +257,11 @@ module Blazerviewed_query_ids = Blazer::Audit.where("created_at > ?", 90.days.ago).group(:query_id).count.keys.compactBlazer::Query.active.where.not(id: viewed_query_ids).update_all(status: "archived")end++ # private+ def self.monotonic_time+ Process.clock_gettime(Process::CLOCK_MONOTONIC)+ endendBlazer.register_adapter "athena", Blazer::Adapters::AthenaAdapterdiff --git a/lib/blazer/data_source.rb b/lib/blazer/data_source.rbindex dd6d9fa1..692882f1 100644--- a/lib/blazer/data_source.rb+++ b/lib/blazer/data_source.rb@@ -233,14 +233,14 @@ module Blazerenddef run_statement_helper(statement, comment, run_id, options)- start_time = Time.now+ start_time = Blazer.monotonic_timecolumns, rows, error =if adapter_instance.parameter_bindingadapter_instance.run_statement(statement.bind_statement, comment, statement.bind_values)elseadapter_instance.run_statement(statement.bind_statement, comment)end- duration = Time.now - start_time+ duration = Blazer.monotonic_time - start_timecache_data = nilcache = !error && (cache_mode == "all" || (cache_mode == "slow" && duration >= cache_slow_threshold))diff --git a/lib/blazer/run_statement.rb b/lib/blazer/run_statement.rbindex bc5727f5..f6d45aba 100644--- a/lib/blazer/run_statement.rb+++ b/lib/blazer/run_statement.rb@@ -17,9 +17,9 @@ module Blazeraudit.save!end- start_time = Time.now+ start_time = Blazer.monotonic_timeresult = data_source.run_statement(statement, options)- duration = Time.now - start_time+ duration = Blazer.monotonic_time - start_timeif Blazer.auditaudit.duration = duration if audit.respond_to?(:duration=)