aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-04-16 11:13:15 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-04-16 11:13:15 -0500
commit702c919b27940d5b46d653d31a89daf2efa674d0 (patch)
tree76fcb96c2d171f5cb211568a83d7191e7fc6cbbc /lib/action_cable
parent5ae546c822f95798bb64cda093bf1c444c829495 (diff)
downloadrails-702c919b27940d5b46d653d31a89daf2efa674d0.tar.gz
rails-702c919b27940d5b46d653d31a89daf2efa674d0.tar.bz2
rails-702c919b27940d5b46d653d31a89daf2efa674d0.zip
Ping pubsub every 2 minutes
Diffstat (limited to 'lib/action_cable')
-rw-r--r--lib/action_cable/server.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb
index 930deec1d7..f7399666bc 100644
--- a/lib/action_cable/server.rb
+++ b/lib/action_cable/server.rb
@@ -1,5 +1,7 @@
module ActionCable
class Server
+ PUBSUB_PING_TIMEOUT = 120
+
cattr_accessor(:logger, instance_reader: true) { Rails.logger }
attr_accessor :registered_channels, :redis_config
@@ -24,7 +26,7 @@ module ActionCable
end
def pubsub
- @pubsub ||= redis.pubsub
+ @pubsub ||= redis.pubsub.tap { |pb| add_pubsub_periodic_timer(pb) }
end
def redis
@@ -71,5 +73,12 @@ module ActionCable
@connections.map(&:statistics)
end
+ protected
+ def add_pubsub_periodic_timer(ps)
+ @pubsub_periodic_timer ||= EventMachine.add_periodic_timer(PUBSUB_PING_TIMEOUT) do
+ logger.info "[ActionCable] Pubsub ping"
+ ps.ping
+ end
+ end
end
end