diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-10-12 12:33:48 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-10-12 12:33:48 -0500 |
commit | d222f7de572f28fc2fa185e9f21cac6f7e6c84f0 (patch) | |
tree | bc3b9edb6e85119f172c1367fd96826367b1948d /lib/action_cable | |
parent | aa3c1154edfacecbbf676af4d8728d8674d97cf4 (diff) | |
download | rails-d222f7de572f28fc2fa185e9f21cac6f7e6c84f0.tar.gz rails-d222f7de572f28fc2fa185e9f21cac6f7e6c84f0.tar.bz2 rails-d222f7de572f28fc2fa185e9f21cac6f7e6c84f0.zip |
Make sure active record queries are logged with the current connection tags
Diffstat (limited to 'lib/action_cable')
-rw-r--r-- | lib/action_cable/connection/tagged_logger_proxy.rb | 5 | ||||
-rw-r--r-- | lib/action_cable/server.rb | 2 | ||||
-rw-r--r-- | lib/action_cable/server/worker.rb | 7 | ||||
-rw-r--r-- | lib/action_cable/server/worker/active_record_connection_management.rb (renamed from lib/action_cable/server/worker/clear_database_connections.rb) | 4 |
4 files changed, 13 insertions, 5 deletions
diff --git a/lib/action_cable/connection/tagged_logger_proxy.rb b/lib/action_cable/connection/tagged_logger_proxy.rb index 854f613f1c..34063c1d42 100644 --- a/lib/action_cable/connection/tagged_logger_proxy.rb +++ b/lib/action_cable/connection/tagged_logger_proxy.rb @@ -4,6 +4,8 @@ module ActionCable # ActiveSupport::TaggedLogging-enhanced Rails.logger, as that logger will reset the tags between requests. # The connection is long-lived, so it needs its own set of tags for its independent duration. class TaggedLoggerProxy + attr_reader :tags + def initialize(logger, tags:) @logger = logger @tags = tags.flatten @@ -22,7 +24,8 @@ module ActionCable protected def log(type, message) - @logger.tagged(*@tags) { @logger.send type, message } + current_tags = tags - @logger.formatter.current_tags + @logger.tagged(*current_tags) { @logger.send type, message } end end end diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb index 919ebd94de..2278509341 100644 --- a/lib/action_cable/server.rb +++ b/lib/action_cable/server.rb @@ -6,6 +6,6 @@ module ActionCable autoload :Configuration, 'action_cable/server/configuration' autoload :Worker, 'action_cable/server/worker' - autoload :ClearDatabaseConnections, 'action_cable/server/worker/clear_database_connections' + autoload :ActiveRecordConnectionManagement, 'action_cable/server/worker/active_record_connection_management' end end diff --git a/lib/action_cable/server/worker.rb b/lib/action_cable/server/worker.rb index d7823ecf93..91496775b8 100644 --- a/lib/action_cable/server/worker.rb +++ b/lib/action_cable/server/worker.rb @@ -5,10 +5,13 @@ module ActionCable include ActiveSupport::Callbacks include Celluloid + attr_reader :connection define_callbacks :work - include ClearDatabaseConnections + include ActiveRecordConnectionManagement def invoke(receiver, method, *args) + @connection = receiver + run_callbacks :work do receiver.send method, *args end @@ -20,6 +23,8 @@ module ActionCable end def run_periodic_timer(channel, callback) + @connection = channel.connection + run_callbacks :work do callback.respond_to?(:call) ? channel.instance_exec(&callback) : channel.send(callback) end diff --git a/lib/action_cable/server/worker/clear_database_connections.rb b/lib/action_cable/server/worker/active_record_connection_management.rb index 722d363a41..1ede0095f8 100644 --- a/lib/action_cable/server/worker/clear_database_connections.rb +++ b/lib/action_cable/server/worker/active_record_connection_management.rb @@ -2,7 +2,7 @@ module ActionCable module Server class Worker # Clear active connections between units of work so the long-running channel or connection processes do not hoard connections. - module ClearDatabaseConnections + module ActiveRecordConnectionManagement extend ActiveSupport::Concern included do @@ -12,7 +12,7 @@ module ActionCable end def with_database_connections - yield + ActiveRecord::Base.logger.tagged(*connection.logger.tags) { yield } ensure ActiveRecord::Base.clear_active_connections! end |