7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/extface/jobs_controller.rb', line 7
def show
response.['Content-Type'] = 'text/event-stream'
@job = Job.find(params[:id])
if @job.completed?
response.stream.write("data: Job #{@job.id} completed!\n\n")
elsif @job.failed?
response.stream.write("data: Job #{@job.id} failed!\n\n")
else
response.stream.write("data: Job #{@job.id} waiting for device connection...\n\n")
Extface.redis_block do |r|
r.subscribe(@job.id) do |on|
on.message do |event, data|
response.stream.write("data: #{data}\n\n") unless data == 'OK'
r.unsubscribe if data == "Job #{@job.id} completed!" || data == "Job #{@job.id} failed!"
end
end
end
end
ensure
response.stream.close
end
|