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.8.5 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.8.4 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.8.3 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.8.1 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.8.0 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.7.2 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.7.1 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.7.0 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.6.0 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.10 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.9 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.8 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.7 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.6 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.5 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.4 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.3 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.2 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.1 app/controllers/my_dashboard/events_controller.rb
my_dashboard-0.5.0 app/controllers/my_dashboard/events_controller.rb