aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2016-06-29 23:15:16 -0700
committerJeremy Daer <jeremydaer@gmail.com>2016-06-29 23:37:07 -0700
commitba9571e1ace2e9a41c3460f7d5eaef17178d637d (patch)
treea1767104e22002b8fea6c7c8bb0779fa84f4e5a7 /actioncable/lib
parentfe054e02b29340c6d9265f9b4ea2ea7d9a872156 (diff)
downloadrails-ba9571e1ace2e9a41c3460f7d5eaef17178d637d.tar.gz
rails-ba9571e1ace2e9a41c3460f7d5eaef17178d637d.tar.bz2
rails-ba9571e1ace2e9a41c3460f7d5eaef17178d637d.zip
Periodic timers: delegate async instance_exec to the worker pool
Diffstat (limited to 'actioncable/lib')
-rw-r--r--actioncable/lib/action_cable/channel/periodic_timers.rb4
-rw-r--r--actioncable/lib/action_cable/server/worker.rb12
2 files changed, 9 insertions, 7 deletions
diff --git a/actioncable/lib/action_cable/channel/periodic_timers.rb b/actioncable/lib/action_cable/channel/periodic_timers.rb
index dab604440f..41511312fc 100644
--- a/actioncable/lib/action_cable/channel/periodic_timers.rb
+++ b/actioncable/lib/action_cable/channel/periodic_timers.rb
@@ -64,9 +64,7 @@ module ActionCable
def start_periodic_timer(callback, every:)
connection.server.event_loop.timer every do
- connection.worker_pool.async_invoke connection do
- instance_exec(&callback)
- end
+ connection.worker_pool.async_exec self, connection: connection, &callback
end
end
diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb
index a638ff72e7..f3a4fc5a5b 100644
--- a/actioncable/lib/action_cable/server/worker.rb
+++ b/actioncable/lib/action_cable/server/worker.rb
@@ -42,16 +42,20 @@ module ActionCable
self.connection = nil
end
- def async_invoke(receiver, method, *args, connection: receiver)
+ def async_exec(receiver, *args, connection:, &block)
+ async_invoke receiver, :instance_exec, *args, connection: connection, &block
+ end
+
+ def async_invoke(receiver, method, *args, connection: receiver, &block)
@executor.post do
- invoke(receiver, method, *args, connection: connection)
+ invoke(receiver, method, *args, connection: connection, &block)
end
end
- def invoke(receiver, method, *args, connection:)
+ def invoke(receiver, method, *args, connection:, &block)
work(connection) do
begin
- receiver.send method, *args
+ receiver.send method, *args, &block
rescue Exception => e
logger.error "There was an exception - #{e.class}(#{e.message})"
logger.error e.backtrace.join("\n")