Class: ActionCable::SubscriptionAdapter::PostgreSQL
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
ChannelPrefix ,
Base
|
|
Inherits: |
ActionCable::SubscriptionAdapter::Base
|
Defined in: | actioncable/lib/action_cable/subscription_adapter/postgresql.rb |
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #broadcast(channel, payload)
- #shutdown
- #subscribe(channel, callback, success_callback = nil)
- #unsubscribe(channel, callback)
- #with_broadcast_connection(&block)
- #with_subscriptions_connection(&block)
- #channel_identifier(channel) private
- #listener private
- #verify!(pg_conn) private
ChannelPrefix
- Included
#broadcast, #subscribe, #unsubscribe, | |
#channel_with_prefix | Returns the channel name, including channel_prefix specified in cable.yml. |
Base
- Inherited
Constructor Details
.new ⇒ PostgreSQL
# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 14
def initialize(*) super @listener = nil end
Instance Method Details
#broadcast(channel, payload)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 19
def broadcast(channel, payload) with_broadcast_connection do |pg_conn| pg_conn.exec("NOTIFY #{pg_conn.escape_identifier(channel_identifier(channel))}, '#{pg_conn.escape_string(payload)}'") end end
#channel_identifier(channel) (private)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 61
def channel_identifier(channel) channel.size > 63 ? OpenSSL::Digest::SHA1.hexdigest(channel) : channel end
#listener (private)
[ GitHub ]#shutdown
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 33
def shutdown listener.shutdown end
#subscribe(channel, callback, success_callback = nil)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 25
def subscribe(channel, callback, success_callback = nil) listener.add_subscriber(channel_identifier(channel), callback, success_callback) end
#unsubscribe(channel, callback)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 29
def unsubscribe(channel, callback) listener.remove_subscriber(channel_identifier(channel), callback) end
#verify!(pg_conn) (private)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 69
def verify!(pg_conn) unless pg_conn.is_a?(PG::Connection) raise "The Active Record database must be PostgreSQL in order to use the PostgreSQL Action Cable storage adapter" end end
#with_broadcast_connection(&block)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 52
def with_broadcast_connection(&block) # :nodoc: ActiveRecord::Base.connection_pool.with_connection do |ar_conn| pg_conn = ar_conn.raw_connection verify!(pg_conn) yield pg_conn end end
#with_subscriptions_connection(&block)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/postgresql.rb', line 37
def with_subscriptions_connection(&block) # :nodoc: ar_conn = ActiveRecord::Base.connection_pool.checkout.tap do |conn| # Action Cable is taking ownership over this database connection, and will # perform the necessary cleanup tasks ActiveRecord::Base.connection_pool.remove(conn) end pg_conn = ar_conn.raw_connection verify!(pg_conn) pg_conn.exec("SET application_name = #{pg_conn.escape_identifier(identifier)}") yield pg_conn ensure ar_conn.disconnect! end