1

私はSinatra基盤上に構築されたrubyweb-/data-serverアプリケーションを持っています。非同期データ転送接続を使用できるように、EventMachineとem-websocketを追加しています。

#! /usr/bin/env ruby

require 'yajl'
require 'json'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
require './Actors/DataProvider.rb'

my_host = '10.2.56.87'
my_web_port = '4004'
my_web_sock = '8008'

EventMachine.epoll  # choose kernel epoll over select for deterministic execution under load
EventMachine.run do

   class SinatraApp < Sinatra::Base

    configure do
      set :bind, '10.2.56.87'
      set :port, '4004'
    end

    encoder = Yajl::Encoder.new
    communicator = DataProvider.new( encoder )

    get '/' do
      redirect '/index-work.html'
    end

    before do
      content_type 'application/json'
    end

    post '/auth' do
    end

    post '/data/:id' do
      puts 'got d i '
    end
  end
  EventMachine::WebSocket.start( :host => my_host, :port => my_web_sock ) do | ws |
    ws.onopen do

    end
    ws.onmessage do

    end
    ws.onclose do

    end
  end
  begin
    SinatraApp.run!
  rescue => ex
    puts "#{ ex.class}: #{ ex.message }"
  end
end

シンサーバーはSinatraにサービスを提供するだけで正常に機能しましたが、EMファウンデーションを追加したので、次のようになります。

/usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:192:in `block (2 levels) in start': undefined method `attach_server' for EventMachine:Module (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:30:in `block (2 levels) in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:23:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `work'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:129:in `block (2 levels) in spawn_missing_workers'
from (eval):6:in `block in fork'
from (eval):6:in `fork'
from (eval):6:in `fork'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:126:in `block in spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `times'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:44:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:37:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:187:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/sinatra-1.3.3/lib/sinatra/base.rb:1350:in `run!'
from /home/devel/ISF_Server/server-work.rb:122:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /home/devel/ISF_Server/server-work.rb:15:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_load'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_program'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide:118:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'         

Thin gemが最近更新されたことに気づきましたが、EMは更新されていません。それが私の次の質問点です。他の誰かが、ThinをEM.runブロック内から実行するべきではないと投稿しましたが、私が構築している例では、このようにしています。

4

1 に答える 1

1

わかった。Marc-Andre Cournoyer と直接やり取りしました。まず、EM.run ブロック内で (Sinatra を介して) This を生成しないでください。

次に、EventMachine live Edition または gem eventmachine-le を必要とする Thin 2 (pre) からエラーが生成されます。

もうね。:D

于 2012-11-27T19:44:53.857 に答える