Sha256: 833dc25251b5bdefb05ca14004eeb80964c6a493c79f091580d9669d4eb94efe

Contents?: true

Size: 924 Bytes

Versions: 11

Compression:

Stored size: 924 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")
      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

11 entries across 11 versions & 1 rubygems

Version Path
extface-0.1.3 app/controllers/extface/jobs_controller.rb
extface-0.1.2 app/controllers/extface/jobs_controller.rb
extface-0.1.1 app/controllers/extface/jobs_controller.rb
extface-0.1.0 app/controllers/extface/jobs_controller.rb
extface-0.0.8 app/controllers/extface/jobs_controller.rb
extface-0.0.7 app/controllers/extface/jobs_controller.rb
extface-0.0.6 app/controllers/extface/jobs_controller.rb
extface-0.0.5 app/controllers/extface/jobs_controller.rb
extface-0.0.3 app/controllers/extface/jobs_controller.rb
extface-0.0.2 app/controllers/extface/jobs_controller.rb
extface-0.0.1 app/controllers/extface/jobs_controller.rb