Class: Upkeep::Rails::Cable::Channel

Inherits:
ActionCable::Channel::Base
  • Object
show all
Defined in:
lib/upkeep/rails/cable/channel.rb

Constant Summary collapse

SUBSCRIBE_NOTIFICATION =
"subscribe_channel.upkeep"
HEARTBEAT_INTERVAL =

Liveness heartbeat: a connected page touches its subscription row on this interval, keeping updated_at fresh so opportunistic pruning only ever removes abandoned subscriptions. Invariant: connected => touched at least every HEARTBEAT_INTERVAL => retained, so this must stay far below config.subscription_ttl (20 minutes vs a 24 hour default). It is a constant because ActionCable fixes periodic timer intervals at class load, before app configuration is readable.

20 * 60

Instance Method Summary collapse

Instance Method Details

#subscribedObject



23
24
25
26
27
28
29
# File 'lib/upkeep/rails/cable/channel.rb', line 23

def subscribed
  if ActiveSupport::Notifications.notifier.listening?(SUBSCRIBE_NOTIFICATION)
    instrumented_subscribe
  else
    subscribe_without_instrumentation
  end
end

#unsubscribedObject



31
32
33
34
35
# File 'lib/upkeep/rails/cable/channel.rb', line 31

def unsubscribed
  Upkeep::Rails.subscriptions.unregister(subscription_id)
rescue KeyError
  nil
end