X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/37e995fb7423b2b353c599e2a1b00bda7c29ee6f..3a822f9f2f0907fd1bdb530390772b7e0f46c9cb:/services/api/lib/audit_logs.rb diff --git a/services/api/lib/audit_logs.rb b/services/api/lib/audit_logs.rb index 8a5a6306b4..2b5e3b8abf 100644 --- a/services/api/lib/audit_logs.rb +++ b/services/api/lib/audit_logs.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'current_api_client' require 'db_current_time' @@ -15,7 +19,7 @@ module AuditLogs File.open(lockfile, File::RDWR|File::CREAT, 0600) do |f| return unless f.flock(File::LOCK_NB|File::LOCK_EX) - sql = "select clock_timestamp() - interval '#{max_age} seconds'" + sql = "select clock_timestamp() - interval '#{'%.9f' % max_age} seconds'" threshold = ActiveRecord::Base.connection.select_value(sql).to_time.utc Rails.logger.info "AuditLogs: deleting logs older than #{threshold}" @@ -40,8 +44,8 @@ module AuditLogs end def self.tidy_in_background - max_age = Rails.configuration.max_audit_log_age - max_batch = Rails.configuration.max_audit_log_delete_batch + max_age = Rails.configuration.AuditLogs.MaxAge.to_i + max_batch = Rails.configuration.AuditLogs.MaxDeleteBatch return if max_age <= 0 || max_batch <= 0 exp = (max_age/14).seconds @@ -58,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