rubyruby-on-rails-3xmppresquexmpp4r

Rails + XMPP bot in background


I'm building a service which basically allows users to chat with a bot, and the bot then does some strange processing with the chat sent by the user, and eventually reply back with some meaningful data. Basically something similar to how Aardvark used (?) to work.

I've the bot working, and listening right now, and I have a separate rails app that will be doing all the other heavy lifting. Both these parts are working fine individually, and now I'm stuck at interfacing the two. My idea is to interface the bot (which is basically a small ruby script) with the rails app via Resque - anything that comes in goes to a queue, gets picked up, and the results then pushed back again to the queue, and then the script would reply back with the results.

I'm not very clear as to how to establish this interface:

  1. Do I need to write a rake task to start / stop / reload the bot
  2. If I run it without rake (supposedly as an independent process monitored by Monit) then how do I interface with Resque or access my rails models ?

I know these might be very trivial questions, but I'm having a hard time understanding which works better, and how to get the setup going.


Solution

  • There are three ways to communicate between your Rails app and this bot daemon:

    1. By calling the Rails app as an HTTP request (pushing/pulling data from Rails app)
    2. By interacting directly with a database the Rails app uses (likely Mysql/Postgres)
    3. By interacting with a Resque work queue system, backed by the Redis database

    When you are enqueuing and pulling Resque jobs off various Job queues, you're just reading/writing to the shared Redis database through an API. Both the bot and the Rails app talk to the Redis DB over the network.

    I recommend running the bot directly as a ruby process or rake task managed by monit. It sounds like you already know how to do this.