Explorar o código

Raise error when timeout not supported

Andrew Kane %!s(int64=9) %!d(string=hai) anos
pai
achega
06d5ef638f
Modificáronse 3 ficheiros con 7 adicións e 5 borrados
  1. 1 0
      CHANGELOG.md
  2. 2 0
      lib/blazer.rb
  3. 4 5
      lib/blazer/data_source.rb

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 - Switched to Chart.js for charts
 - Better output for explain
 - Support for MySQL timeouts
+- Raise error when timeout not supported
 
 ## 1.2.1
 

+ 2 - 0
lib/blazer.rb

@@ -6,6 +6,8 @@ require "blazer/data_source"
 require "blazer/engine"
 
 module Blazer
+  class TimeoutNotSupported < StandardError; end
+
   class << self
     attr_accessor :audit
     attr_reader :time_zone

+ 4 - 5
lib/blazer/data_source.rb

@@ -84,6 +84,8 @@ module Blazer
                 connection_model.connection.execute("SET statement_timeout = #{timeout.to_i * 1000}")
               elsif mysql?
                 connection_model.connection.execute("SET max_execution_time = #{timeout.to_i * 1000}")
+              else
+                raise Blazer::TimeoutNotSupported, "Timeout not supported for #{adapter_name} adapter"
               end
             end
 
@@ -146,11 +148,8 @@ module Blazer
     def in_transaction
       if use_transaction?
         connection_model.transaction do
-          begin
-            yield
-          ensure
-            raise ActiveRecord::Rollback
-          end
+          yield
+          raise ActiveRecord::Rollback
         end
       else
         yield