C
C
caution2014-06-12 19:07:26
Ruby on Rails
caution, 2014-06-12 19:07:26

Does Thin with Rails Live Streaming work?

Has anyone used Thin with Live Streams?
I used the sorts from the 401 RailsCasts lessons, but instead of Puma I put Thin. Puma is ok. With Thin, everything just hangs for me, and I have to kill the process. Although the docs say that it should work with Thin.
UPD:
I tried to run in this way
thin start --threaded
in the end

Using rack adapter
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
127.0.0.1 - - [12/Jun/2014 19:22:36] "GET / HTTP/1.1" 200 - 0.1773
127.0.0.1 - - [12/Jun/2014 19:22:36] "GET /layout.css?body=1 HTTP/1.1" 304 - 0.0109
127.0.0.1 - - [12/Jun/2014 19:22:36] "GET /application.css?body=1 HTTP/1.1" 304 - 0.0204
/home/eugeny/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/thread.rb:187:in `handle_interrupt': stream closed (IOError)
  from /home/eugeny/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/thread.rb:187:in `pop'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/eventmachine-1.0.3/lib/eventmachine.rb:950:in `run_deferred_callbacks'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/lib/thin/controllers/controller.rb:87:in `start'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
  from /home/eugeny/.rvm/gems/[email protected]_test/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
  from /home/eugeny/.rvm/gems/[email protected]_test/bin/thin:23:in `load'
  from /home/eugeny/.rvm/gems/[email protected]_test/bin/thin:23:in `<main>'
  from /home/eugeny/.rvm/gems/[email protected]_test/bin/ruby_executable_hooks:15:in `eval'
  from /home/eugeny/.rvm/gems/[email protected]_test/bin/ruby_executable_hooks:15:in `<main>'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimitriy, 2014-06-13
@caution

It works, with limitations, there is no support in the main branch, it turns on like this:

def stream
    response.headers['Content-Type'] = 'text/event-stream'
    sse = SSE.new(response.stream, retry: 5000, event: 'notify')

    3.times do |a|
      sse.write({ class_id: __id__ })
      sleep 3
    end

    rescue IOError
      logger.info('Client alive channel')
    ensure
      response.stream.close
end

event = new EventSource('/stream')
event.addEventListener 'notify', (e)->
  console.log(e.data)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question