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

::ActiveSupport::DescendantsTracker - self

descendants

See additional method definition at line 104.

subclasses

See additional method definition at line 100.

clear, disable_clear!, reject!,
store_inherited

This is the only method that is not thread safe, but is only ever called during the eager loading phase.

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 19

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 70

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

.__callbacks?Boolean (rw)

[ GitHub ]

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

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

Instance Attribute Details

#__callbacks (readonly)

[ GitHub ]

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

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

#__callbacks?Boolean (readonly)

[ GitHub ]

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

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

#executor (readonly)

[ GitHub ]

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

attr_reader :executor

#stopping?Boolean (readonly)

[ GitHub ]

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

def stopping?
  @executor.shuttingdown?
end

Instance Method Details

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

[ GitHub ]

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

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 50

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 30

def halt
  @executor.shutdown
end

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

[ GitHub ]

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

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 68

def logger
  ActionCable.server.logger
end

#work(connection, &block)

[ GitHub ]

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

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

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