9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/profiler/api/events_controller.rb', line 9
def subscribe
response.["Content-Type"] = "text/event-stream"
response.["Cache-Control"] = "no-cache"
response.["X-Accel-Buffering"] = "no"
sse = ActionController::Live::SSE.new(response.stream, retry: 3000, event: "profile_update")
id = Profiler::SSE.current.subscribe(params[:token], Array(params[:collectors]))
begin
loop do
event = Profiler::SSE.current.wait_for_event(id, timeout: 30)
if event
sse.write(event)
else
sse.write({}, event: "heartbeat")
end
end
rescue ActionController::Live::ClientDisconnected, IOError
ensure
Profiler::SSE.current.unsubscribe(id)
sse.close
end
end
|