aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/server/worker/active_record_connection_management.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2015-12-14 15:48:54 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2015-12-14 15:48:54 +0100
commitbf40bddfceebaff637161be6c5d992d6978679ff (patch)
treeb3541d5ec5015ab9459d1970a9f10fd37c0156c3 /actioncable/lib/action_cable/server/worker/active_record_connection_management.rb
parent4073a3e3fe77141d09ed767224a1089796de2f7d (diff)
downloadrails-bf40bddfceebaff637161be6c5d992d6978679ff.tar.gz
rails-bf40bddfceebaff637161be6c5d992d6978679ff.tar.bz2
rails-bf40bddfceebaff637161be6c5d992d6978679ff.zip
Get ready to merge into Rails
Diffstat (limited to 'actioncable/lib/action_cable/server/worker/active_record_connection_management.rb')
-rw-r--r--actioncable/lib/action_cable/server/worker/active_record_connection_management.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/actioncable/lib/action_cable/server/worker/active_record_connection_management.rb b/actioncable/lib/action_cable/server/worker/active_record_connection_management.rb
new file mode 100644
index 0000000000..ecece4e270
--- /dev/null
+++ b/actioncable/lib/action_cable/server/worker/active_record_connection_management.rb
@@ -0,0 +1,22 @@
+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 ActiveRecordConnectionManagement
+ extend ActiveSupport::Concern
+
+ included do
+ if defined?(ActiveRecord::Base)
+ set_callback :work, :around, :with_database_connections
+ end
+ end
+
+ def with_database_connections
+ connection.logger.tag(ActiveRecord::Base.logger) { yield }
+ ensure
+ ActiveRecord::Base.clear_active_connections!
+ end
+ end
+ end
+ end
+end \ No newline at end of file