Class: Gaku::RealtimeController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Gaku::RealtimeController
- Includes:
- ActionController::Live
- Defined in:
- app/controllers/gaku/realtime_controller.rb
Instance Method Summary collapse
-
#exam_portion_scores ⇒ Object
change SSE.new with rails SSE object when is released github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/live.rb.
Instance Method Details
#exam_portion_scores ⇒ Object
change SSE.new with rails SSE object when is released github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/live.rb
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/gaku/realtime_controller.rb', line 8 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 |