Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Changed

- [Deferred] Increase default retry limit to 20 and update default retry backoff to `(attempt**4) + 10 + (rand(15) * attempt)` by [@anuj-pal27](https://github.com/anuj-pal27) (#271).
- Update `Rage::Cable` to use the new `PubSub` module (#281).

## [1.23.0] - 2026-04-15

Expand Down
16 changes: 0 additions & 16 deletions lib/rage/cable/adapters/base.rb

This file was deleted.

128 changes: 0 additions & 128 deletions lib/rage/cable/adapters/redis.rb

This file was deleted.

32 changes: 18 additions & 14 deletions lib/rage/cable/cable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
# ```
#
module Rage::Cable
PUBSUB_BROADCASTER_ID = "cable"
private_constant :PUBSUB_BROADCASTER_ID

# Create a new Cable application.
#
# @example
# map "/cable" do
# run Rage.cable.application
# end
def self.application
# explicitly initialize the adapter
__adapter

handler = __build_handler(__protocol)
accept_response = [0, __protocol.protocol_definition, []]

Expand All @@ -61,6 +61,14 @@ def self.application
chain
end

# @private
def self.__initialize
if (adapter = Rage.config.pubsub.adapter)
adapter.add_broadcaster(PUBSUB_BROADCASTER_ID, __protocol)
@__adapter = adapter
end
end

# @private
def self.__router
@__router ||= Router.new
Expand All @@ -71,11 +79,6 @@ def self.__protocol
@__protocol ||= Rage.config.cable.protocol.tap { |protocol| protocol.init(__router) }
end

# @private
def self.__adapter
@__adapter ||= Rage.config.cable.adapter
end

# @private
def self.__build_handler(protocol)
klass = Class.new do
Expand Down Expand Up @@ -142,7 +145,7 @@ def log_error(e)
def self.broadcast(stream, data)
Rage::Telemetry.tracer.span_cable_stream_broadcast(stream:) do
__protocol.broadcast(stream, data)
__adapter&.publish(stream, data)
@__adapter&.publish(PUBSUB_BROADCASTER_ID, stream, data)
end

true
Expand Down Expand Up @@ -174,11 +177,6 @@ def self.broadcast(stream, data)
# end
# end

module Adapters
autoload :Base, "rage/cable/adapters/base"
autoload :Redis, "rage/cable/adapters/redis"
end

module Protocols
end

Expand All @@ -191,3 +189,9 @@ module Protocols
require_relative "channel"
require_relative "connection"
require_relative "router"

if Rage.config.internal.initialized?
Rage::Cable.__initialize
else
Rage.config.after_initialize { Rage::Cable.__initialize }
end
28 changes: 1 addition & 27 deletions lib/rage/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,33 +640,6 @@ def middlewares
end
end
end

# @private
def config
@config ||= begin
config_file = Rage.root.join("config/cable.yml")

if config_file.exist?
yaml = ERB.new(config_file.read).result
YAML.safe_load(yaml, aliases: true, symbolize_names: true)[Rage.env.to_sym] || {}
else
{}
end
end
end

# @private
def adapter_config
config.except(:adapter)
end

# @private
def adapter
case config[:adapter]
when "redis"
Rage::Cable::Adapters::Redis.new(adapter_config)
end
end
end

class PublicFileServer
Expand Down Expand Up @@ -1056,6 +1029,7 @@ def initialize
def config
@config ||= begin
config_file = Rage.root.join("config/pubsub.yml")
config_file = Rage.root.join("config/cable.yml") unless config_file.exist?

config = if config_file.exist?
yaml = ERB.new(config_file.read).result
Expand Down
Loading
Loading