diff options
author | Matthew Draper <matthew@trebex.net> | 2016-03-02 02:56:53 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-03-02 02:56:53 +1030 |
commit | 541e4abb4b3710a384aefac83cafd0ab878c60bf (patch) | |
tree | 55603da9b6f9407a24c68e1d1fd53e109c4131e7 /actioncable/lib/action_cable/server/worker.rb | |
parent | ecdc0fbc872ea734adf29b3f9f3463b916235286 (diff) | |
parent | 60b53e9883bfd9f4edb640dbe2de89227b875e09 (diff) | |
download | rails-541e4abb4b3710a384aefac83cafd0ab878c60bf.tar.gz rails-541e4abb4b3710a384aefac83cafd0ab878c60bf.tar.bz2 rails-541e4abb4b3710a384aefac83cafd0ab878c60bf.zip |
Merge pull request #23807 from matthewd/executor
Publish AS::Executor and AS::Reloader APIs
Diffstat (limited to 'actioncable/lib/action_cable/server/worker.rb')
-rw-r--r-- | actioncable/lib/action_cable/server/worker.rb | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb index b920b880db..49cbaec0c0 100644 --- a/actioncable/lib/action_cable/server/worker.rb +++ b/actioncable/lib/action_cable/server/worker.rb @@ -20,6 +20,26 @@ module ActionCable ) end + # Stop processing work: any work that has not already started + # running will be discarded from the queue + def halt + @pool.kill + end + + def stopping? + @pool.shuttingdown? + end + + def work(connection) + self.connection = connection + + run_callbacks :work do + yield + end + ensure + self.connection = nil + end + def async_invoke(receiver, method, *args) @pool.post do invoke(receiver, method, *args) @@ -27,19 +47,15 @@ module ActionCable end def invoke(receiver, method, *args) - begin - self.connection = receiver - - run_callbacks :work do + work(receiver) do + begin receiver.send method, *args - end - rescue Exception => e - logger.error "There was an exception - #{e.class}(#{e.message})" - logger.error e.backtrace.join("\n") + 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 + receiver.handle_exception if receiver.respond_to?(:handle_exception) + end end end @@ -50,14 +66,8 @@ module ActionCable end def run_periodic_timer(channel, callback) - begin - self.connection = channel.connection - - run_callbacks :work do - callback.respond_to?(:call) ? channel.instance_exec(&callback) : channel.send(callback) - end - ensure - self.connection = nil + work(channel.connection) do + callback.respond_to?(:call) ? channel.instance_exec(&callback) : channel.send(callback) end end |