aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/server/worker.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2016-01-08 20:09:25 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2016-01-08 20:09:25 +0100
commit36fe3015644284dfbd7716c1d844dd8ad68b88c2 (patch)
treed111571f1a34efba019097993b074123c943e93e /actioncable/lib/action_cable/server/worker.rb
parent3b7ccadfc1c8dfec61af898167e1300b17f5cf25 (diff)
downloadrails-36fe3015644284dfbd7716c1d844dd8ad68b88c2.tar.gz
rails-36fe3015644284dfbd7716c1d844dd8ad68b88c2.tar.bz2
rails-36fe3015644284dfbd7716c1d844dd8ad68b88c2.zip
Revert "Move async execution from celluloid to concurrent-ruby"
Diffstat (limited to 'actioncable/lib/action_cable/server/worker.rb')
-rw-r--r--actioncable/lib/action_cable/server/worker.rb55
1 files changed, 13 insertions, 42 deletions
diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb
index 3b6c6d44a1..e063b2a2e1 100644
--- a/actioncable/lib/action_cable/server/worker.rb
+++ b/actioncable/lib/action_cable/server/worker.rb
@@ -1,68 +1,39 @@
+require 'celluloid'
require 'active_support/callbacks'
-require 'active_support/core_ext/module/attribute_accessors_per_thread'
-require 'concurrent'
module ActionCable
module Server
# Worker used by Server.send_async to do connection work in threads. Only for internal use.
class Worker
include ActiveSupport::Callbacks
+ include Celluloid
- thread_mattr_accessor :connection
+ attr_reader :connection
define_callbacks :work
include ActiveRecordConnectionManagement
- def initialize(max_size: 5)
- @pool = Concurrent::ThreadPoolExecutor.new(
- min_threads: 1,
- max_threads: max_size,
- max_queue: 0,
- )
- end
-
- def async_invoke(receiver, method, *args)
- @pool.post do
- invoke(receiver, method, *args)
- end
- end
-
def invoke(receiver, method, *args)
- begin
- self.connection = receiver
+ @connection = receiver
- run_callbacks :work do
- receiver.send method, *args
- end
- rescue Exception => e
- logger.error "There was an exception - #{e.class}(#{e.message})"
- logger.error e.backtrace.join("\n")
-
- receiver.handle_exception if receiver.respond_to?(:handle_exception)
- ensure
- self.connection = nil
+ run_callbacks :work do
+ receiver.send method, *args
end
- end
+ rescue Exception => e
+ logger.error "There was an exception - #{e.class}(#{e.message})"
+ logger.error e.backtrace.join("\n")
- def async_run_periodic_timer(channel, callback)
- @pool.post do
- run_periodic_timer(channel, callback)
- end
+ receiver.handle_exception if receiver.respond_to?(:handle_exception)
end
def run_periodic_timer(channel, callback)
- begin
- self.connection = channel.connection
+ @connection = channel.connection
- run_callbacks :work do
- callback.respond_to?(:call) ? channel.instance_exec(&callback) : channel.send(callback)
- end
- ensure
- self.connection = nil
+ run_callbacks :work do
+ callback.respond_to?(:call) ? channel.instance_exec(&callback) : channel.send(callback)
end
end
private
-
def logger
ActionCable.server.logger
end