Skip to content

Instantly share code, notes, and snippets.

@seigel
Created October 24, 2013 15:59
Show Gist options
  • Save seigel/7139923 to your computer and use it in GitHub Desktop.
Save seigel/7139923 to your computer and use it in GitHub Desktop.
module Dashing
class EventsController < ApplicationController
include ActionController::Live
respond_to :html
def index
response.headers['Content-Type'] = 'text/event-stream'
response.headers['X-Accel-Buffering'] = 'no'
redis = Redis.new
redis.psubscribe("#{Dashing.config.redis_namespace}.*") do |on|
on.pmessage do |pattern, event, data|
response.stream.write("data: #{data}\n\n")
end
end
rescue IOError
logger.info "[Dashing][#{Time.now.utc.to_s}] Stream closed"
ensure
redis.quit
response.stream.close
end
end
end
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment