Created
October 24, 2013 15:59
-
-
Save seigel/7139923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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