Sha256: 185d05c83cdffa8e4884f9036163355f42c3eb06aac95436274123fdd56e2995

Contents?: true

Size: 866 Bytes

Versions: 16

Compression:

Stored size: 866 Bytes

Contents

require 'gaku/streamer/sse'

class Gaku::RealtimeController < ApplicationController
  include ActionController::Live

  # change SSE.new with rails SSE object when is released
  # https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/live.rb
  def exam_portion_scores
    response.headers['Content-Type'] = 'text/event-stream'
    conn = ActiveRecord::Base.connection
    sse = Streamer::SSE.new(response.stream)
    begin
      loop do
        conn.execute 'LISTEN update_exam_portion_score'
        conn.raw_connection.wait_for_notify do |_event, _pid, score|
          sse.write(score, event: 'update.examPortionScore')
        end
      end
    rescue IOError
      sse.close
      conn.execute 'UNLISTEN update_exam_portion_score'
    ensure
      sse.close
      conn.execute 'UNLISTEN update_exam_portion_score'
    end
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gaku_frontend-0.3.0 app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.3.0.pre.4 app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.3.0.pre.3 app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.3.0.pre.2 app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.3.0.pre.1 app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.3.0.pre.0 app/controllers/gaku/realtime_controller.rb
gaku-0.2.4 frontend/app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.2.4 app/controllers/gaku/realtime_controller.rb
gaku-0.2.3 frontend/app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.2.3 app/controllers/gaku/realtime_controller.rb
gaku-0.2.2 frontend/app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.2.2 app/controllers/gaku/realtime_controller.rb
gaku-0.2.1 frontend/app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.2.1 app/controllers/gaku/realtime_controller.rb
gaku-0.2.0 frontend/app/controllers/gaku/realtime_controller.rb
gaku_frontend-0.2.0 app/controllers/gaku/realtime_controller.rb