Make removal of topic columns more resilient to deploys

This commit is contained in:
Sam
2016-12-05 12:11:46 +11:00
parent 33d0a23d84
commit 1db9d17756
4 changed files with 77 additions and 1 deletions

View File

@ -110,6 +110,32 @@ class ApplicationController < ActionController::Base
end
end
def self.last_ar_cache_reset
@last_ar_cache_reset
end
def self.last_ar_cache_reset=(val)
@last_ar_cache_reset
end
rescue_from ActiveRecord::StatementInvalid do |e|
last_cache_reset = ApplicationController.last_ar_cache_reset
if e.message =~ /UndefinedColumn/ && (last_cache_reset.nil? || last_cache_reset < 30.seconds.ago)
Rails.logger.warn "Clear Active Record cache cause schema appears to have changed!"
ApplicationController.last_ar_cache_reset = Time.zone.now
ActiveRecord::Base.connection.query_cache.clear
(ActiveRecord::Base.connection.tables - %w[schema_migrations]).each do |table|
table.classify.constantize.reset_column_information rescue nil
end
end
raise e
end
class PluginDisabled < StandardError; end
# Handles requests for giant IDs that throw pg exceptions