Sha256: 63c980610c1ae264e885c5996f685f1f08fc0380f3843e839f6792792656969c

Contents?: true

Size: 1015 Bytes

Versions: 13

Compression:

Stored size: 1015 Bytes

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")
        Extface.redis_block do |r|
          r.subscribe(@job.id) do |on|
            on.message do |event, data|
              #p "data: #{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!"
            end
          end
        end
      end
    ensure
      response.stream.close
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
extface-0.3.0 app/controllers/extface/jobs_controller.rb
extface-0.2.5 app/controllers/extface/jobs_controller.rb
extface-0.2.4 app/controllers/extface/jobs_controller.rb
extface-0.2.3 app/controllers/extface/jobs_controller.rb
extface-0.2.2 app/controllers/extface/jobs_controller.rb
extface-0.2.1 app/controllers/extface/jobs_controller.rb
extface-0.2.0 app/controllers/extface/jobs_controller.rb
extface-0.1.9 app/controllers/extface/jobs_controller.rb
extface-0.1.8 app/controllers/extface/jobs_controller.rb
extface-0.1.7 app/controllers/extface/jobs_controller.rb
extface-0.1.6 app/controllers/extface/jobs_controller.rb
extface-0.1.5 app/controllers/extface/jobs_controller.rb
extface-0.1.4 app/controllers/extface/jobs_controller.rb