瀏覽代碼

Use constant for timeout errors

Andrew Kane 9 年之前
父節點
當前提交
d308bf3fbc
共有 2 個文件被更改,包括 6 次插入1 次删除
  1. 5 0
      lib/blazer.rb
  2. 1 1
      lib/blazer/data_source.rb

+ 5 - 0
lib/blazer.rb

@@ -25,6 +25,11 @@ module Blazer
   self.check_schedules = ["1 day", "1 hour", "5 minutes"]
 
   TIMEOUT_MESSAGE = "Query timed out :("
+  TIMEOUT_ERRORS = [
+    "canceling statement due to statement timeout", # postgres
+    "cancelled on user's request", # redshift
+    "system requested abort" # redshift
+  ]
 
   def self.time_zone=(time_zone)
     @time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]

+ 1 - 1
lib/blazer/data_source.rb

@@ -99,7 +99,7 @@ module Blazer
             end
           rescue ActiveRecord::StatementInvalid => e
             error = e.message.sub(/.+ERROR: /, "")
-            error = Blazer::TIMEOUT_MESSAGE if error.include?("canceling statement due to statement timeout") || error.include?("cancelled on user's request") || error.include?("system requested abort")
+            error = Blazer::TIMEOUT_MESSAGE if Blazer::TIMEOUT_ERRORS.any? { |e| error.include?(e) }
           end
         end