I think the main issue here is that you need another solution for messaging (IPC-like, not IM) rather than trying to bend Resque which is “just” a queue. Some of the options are amqp gem (AMQP protocol) or zmq gem (ZeroMQ protocol), but you can also use plain old UNIX sockets via Ruby standard library Socket class (good examples). They all have different pros and cons, so it’s up to you and your needs.
The interaction might look like something like this:
- Bot starts.
- Bot starts listening for IPC messages.
- Bot receives a query from sender (via XMPP).
- Bot queues a job via Resque.
- Job calls the Rails app via HTTP.
- Rails app does its share of work.
- Someone or something resolves whatever was the query and enters the result via Rails app.
- Rails app sends the result using some IPC method to the bot.
- Bot sends the results to the original sender (via XMPP).
There can be some changes as usual. For example, I think you don’t need Resque at all. The bot can simply pass the request immediately to the Rails app. However, it depends on load, time to respond you want to achieve, you current architecture, etc. Maybe the Resque job can wait for the Rails app to return the result and then the job (not the Rails app) would use IPC. There are other variations…
Do I need to write a rake task to start / stop / reload the bot
No, you don’t. It is up to you how and when you run it. After all, Rake can be viewed just as a convenient way to put multiple Ruby scripts together and create dependencies between them. If you think there will be other tasks around the bot than just running it (some cleaning up, deployment, etc.), it will be good to use Rake for convenience. If you haven’t already, refactor bot’s logic to class and use Rake task to initialize it. But it will also be fine if you leave it, and just run your script as-is (using monit, your custom init.d script, ad-hoc, etc.).
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 ?
Rake doesn’t have any effect on this. It doesn’t matter from OS perspective if you run Resque via Rake and your bot via Rake or as a standalone script. They will be different processes anyway. Also, keep in mind that Resque needs Redis to be running somewhere.
I know these might be very trivial questions
No at all. I think it’ll take some time before issues like could be considered trivial.