0

I have this code in Faye rackup script:

faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
faye_server.add_extension(ServerAuth.new)

server_uri = URI.parse(BacklinkHealth::FAYE_SERVER)

faye_server.on(:subscribe) do |client_id, channel|
  puts "subscribed #{channel}"
  if channel.starts_with?('/pagination')    
    website_id = channel.split('/')[2]
    page = channel.split('/')[3]
    app = ActionDispatch::Integration::Session.new(Rails.application)
    app.get app.pagination_website_backlinks_path(website_id, :page => page)    
    message = {:channel => channel, :data => app.response.body, :ext => {:auth_token => BacklinkHealth::FAYE_TOKEN}}        
    puts 'started HTTP post'
    Net::HTTP.post_form(server_uri, :message => message.to_json)
    puts 'finished HTTP post'
  end
end

The problem is that the execution comes to "started HTTP post" and then it takes more than a minute for the message to be registered at the client-side javascript. The messge "finished HTTP post" is never printed :( I don't understand what is going on.

If I try to execute an identical HTTP post from Rails console, it goes through in an instant although it did happen once or twice that it took a minute.

Any ideas?

davidhq
  • 4,660
  • 6
  • 30
  • 40

1 Answers1

0

It's much better to use this:

require 'eventmachine'

EM.run {
    client = Faye::Client.new(BacklinkHealth::FAYE_SERVER)
    client.publish(channel, 'pagination' => pagination)
}

than Http requests... I couldn't get this to work with authentication (yet) but I will.

davidhq
  • 4,660
  • 6
  • 30
  • 40