123456789_123456789_123456789_123456789_123456789_

Class: ActionCable::Server::Worker

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Object
Defined in: actioncable/lib/action_cable/server/worker.rb,
actioncable/lib/action_cable/server/worker/active_record_connection_management.rb

Overview

Worker used by Server.send_async to do connection work in threads.

Constant Summary

::ActiveSupport::Callbacks - Included

CALLBACK_FILTER_TYPES

::ActiveSupport::Callbacks - Attributes & Methods

Class Method Summary

Instance Attribute Summary

Instance Method Summary

ActiveRecordConnectionManagement - Included

::ActiveSupport::Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

#halted_callback_hook

A hook invoked every time a before callback is halted.

Constructor Details

.new(max_size: 5) ⇒ Worker

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 21

def initialize(max_size: 5)
  @executor = Concurrent::ThreadPoolExecutor.new(
    name: "ActionCable",
    min_threads: 1,
    max_threads: max_size,
    max_queue: 0,
  )
end

Class Attribute Details

.__callbacks (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 69

class_attribute :__callbacks, instance_writer: false, instance_predicate: false, default: {}

Instance Attribute Details

#__callbacks (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 69

class_attribute :__callbacks, instance_writer: false, instance_predicate: false, default: {}

#executor (readonly)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 19

attr_reader :executor

#stopping?Boolean (readonly)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 36

def stopping?
  @executor.shuttingdown?
end

Instance Method Details

#async_exec(receiver, *args, connection:, &block)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 48

def async_exec(receiver, *args, connection:, &block)
  async_invoke receiver, :instance_exec, *args, connection: connection, &block
end

#async_invoke(receiver, method, *args, connection: receiver, &block)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 52

def async_invoke(receiver, method, *args, connection: receiver, &block)
  @executor.post do
    invoke(receiver, method, *args, connection: connection, &block)
  end
end

#halt

Stop processing work: any work that has not already started running will be discarded from the queue

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 32

def halt
  @executor.shutdown
end

#invoke(receiver, method, *args, connection:, &block)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 58

def invoke(receiver, method, *args, connection:, &block)
  work(connection) do
    receiver.send method, *args, &block
  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)
  end
end

#logger (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 70

def logger
  ActionCable.server.logger
end

#work(connection, &block)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/server/worker.rb', line 40

def work(connection, &block)
  self.connection = connection

  run_callbacks :work, &block
ensure
  self.connection = nil
end