Asynchronous calling methods with Ruby, as with Ajax

I work with XMPP, and I have a message callback that is activated in the event of each sent message. My goal is to send the data arriving as a message to the API in the callback, and based on the response, send something back using the XMPP client.

  • User type message (browser chat client)
  • The message is sent to the server via XMPP
  • The message is sent to the API
  • Answer received.
  • The response is sent back to the chat client.

My code for this is as follows

admin_muc_client.activate_message_callbacks do |m|            
  sender    = m.from.resource
  room_slug = m.from.node
  message   = m.body                  

  r = HTTParty.get('http://example.com/api/v1/query?msg=message')
  Rails.logger.debug(r.inspect)
  admin_muc_client.send_message("Message #{r.body}") if m.from.resource != 'admin'
end

, , , API , . - AJAX Javascript, , , . Ruby?

delayed_job backgroundrb, . -, .

, . , RabbitMQ, , , .

+5
1

girl_friday? wiki -

girl_friday - Ruby . -, , , , . Ruby-, Rails 3.

zillions (Resque, dj ..)? girl_friday , : girl_friday Rails- concurrency. , , , .. . Ruby.

. : , . , . girl_friday Threads , , Ruby . JRuby, Rubinius 1.2 Ruby 1.9.2 . Ruby 1.8 - .

, , .

+5

All Articles