Sha256: 7fac636279778755146d1cd7fe492c77ce54f35f68721cb625f71fd5ec893c52
Contents?: true
Size: 836 Bytes
Versions: 22
Compression:
Stored size: 836 Bytes
Contents
module MyDashboard class EventsController < ApplicationController include ActionController::Live def index response.headers['Content-Type'] = 'text/event-stream' response.headers['X-Accel-Buffering'] = 'no' response.stream.write latest_events @redis = MyDashboard.redis @redis.psubscribe("#{MyDashboard.config.redis_namespace}.*") do |on| on.pmessage do |pattern, event, data| response.stream.write("data: #{data}\n\n") end end rescue IOError logger.info "[MyDashboard][#{Time.now.utc.to_s}] Stream closed" ensure @redis.quit response.stream.close end def latest_events events = MyDashboard.redis.hvals("#{MyDashboard.config.redis_namespace}.latest") events.map { |v| "data: #{v}\n\n" }.join end end end
Version data entries
22 entries across 22 versions & 1 rubygems
Version | Path |
---|---|
my_dashboard-0.4.2 | app/controllers/my_dashboard/events_controller.rb |
my_dashboard-0.4.1 | app/controllers/my_dashboard/events_controller.rb |