5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/dashing/events_controller.rb', line 5
def index
@redis = Dashing.redis
response.['Content-Type'] = 'text/event-stream'
response.['X-Accel-Buffering'] = 'no'
response.stream.write latest_events
@redis.with do |redis_connection|
redis_connection.psubscribe("#{Dashing.config.redis_namespace}.*") do |on|
on.pmessage do |pattern, event, data|
response.stream.write("data: #{data}\n\n")
end
end
end
rescue IOError
logger.info "[Dashing][#{Time.now.utc.to_s}] Stream closed"
ensure
@redis.shutdown { |redis_connection| redis_connection.quit }
response.stream.close
end
|