18870: git stuff
[arvados.git] / services / api / lib / audit_logs.rb
index e97f65a97397c86474fa69d190e92cd1fabfe8ce..2b5e3b8abff2d14ddebea3008aa6774280c466f9 100644 (file)
@@ -44,7 +44,7 @@ module AuditLogs
   end
 
   def self.tidy_in_background
-    max_age = Rails.configuration.AuditLogs.MaxAge
+    max_age = Rails.configuration.AuditLogs.MaxAge.to_i
     max_batch = Rails.configuration.AuditLogs.MaxDeleteBatch
     return if max_age <= 0 || max_batch <= 0
 
@@ -62,7 +62,12 @@ module AuditLogs
       rescue => e
         Rails.logger.error "#{e.class}: #{e}\n#{e.backtrace.join("\n\t")}"
       ensure
-        ActiveRecord::Base.connection.close
+        # Rails 5.1+ makes test threads share a database connection, so we can't
+        # close a connection shared with other threads.
+        # https://github.com/rails/rails/commit/deba47799ff905f778e0c98a015789a1327d5087
+        if Rails.env != "test"
+          ActiveRecord::Base.connection.close
+        end
       end
     end
   end