Sha256: afd3d30e1f84e4b84d44b4f080f3c7d99cc95b11c1f25ff9cb8a6c59c98b332a
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
require_dependency "extface/application_controller" module Extface class JobsController < ApplicationController include ActionController::Live def show response.headers['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 #redis = Redis.new response.stream.write("data: Job #{@job.id} waiting for device connection...\n\n") Timeout.timeout(Extface.device_timeout) do #never stay too long, TODO add SSE option to reconnect Extface.redis_block do |r| r.subscribe(@job.id) do |on| on.message do |event, data| p "@@@@ #{event}: #{data}\n\n" response.stream.write("data: #{data}\n\n") unless data == 'OK' r.unsubscribe if data == "Job #{@job.id} completed!" || data == "Job #{@job.id} failed!" #FIXME stupid end end end end end rescue Timeout::Error #TODO invite reconnect ensure response.stream.close end end end
Version data entries
4 entries across 4 versions & 1 rubygems