1

したがって、基本的に私の目標は、ジョブを処理し、http を介して他のアプリに通知する軽量の Ruby デーモン (または sidekiq/resque ワーカー) を取得することです。アプリ自体は http リクエストを受信する必要がないため、ラックをできるだけ軽量に保つ必要はありません。ループで実行できるかなりの数の Ruby コード{}

そのため、EventMachine のリアクター パターンを使用せず、代わりにファイバー アプローチを使用しようとしています。このコンテキストで EM.run または EM.stop をどこに配置しますか? Thread.new { EM.run }はファイバー対応ではないようです。これに代わるem-synchronyはありますか?

#slow=true injects a sleep 3, so page 2 callback should output faster
require 'em-http-request'
require 'fiber'
def http_get(url)
  f = Fiber.current
  http = EventMachine::HttpRequest.new(url).get

  # resume fiber once http call is done
  http.callback { f.resume(http) }
  http.errback  { f.resume(http) }

  return Fiber.yield
end

puts "fetching some data from database for request params"
EventMachine.run do
  Fiber.new{
    page = http_get('http://localhost:3000/status?slow=true')
    puts "notified external page it responded with: #{page.response_header.status}"
  }.resume
  Fiber.new{
    page = http_get('http://localhost:4000/status')
    puts "notified external page 2 it responded with: #{page.response_header.status}"
  }.resume
  puts "Finishised notification task"
end
puts "Moving on to next task as fast as possible"
4

1 に答える 1