Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the main issues 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 <a href="http://rubyamqp.info" rel="nofollow">amqp gem</a> (AMQP protocol) or <a href="https://github.com/zeromq/rbzmq" rel="nofollow">zmq gem</a> (ZeroMQ protocol), but you can also use plain old UNIX sockets via Ruby standard library Socket class (<a href="http://www.jstorimer.com/2012/04/19/intro-to-ruby-ipc.html" rel="nofollow">good examples</a>). They all have different pros and cons, so its probably up to you.</p> <p>Then, the interaction might look like something like this:</p> <ol> <li>Bot starts.</li> <li>Bot starts listening for IPC messages.</li> <li>Bot receives a query from sender (via XMPP).</li> <li>Bot queues a job via Resque.</li> <li>Job calls the Rails app via HTTP.</li> <li>Rails app does its share of work.</li> <li>Someone or something resolves whatever was the query and enters a result via Rails app.</li> <li>Rails app sends the result using some IPC method to the bot.</li> <li>Bot sends the results to the original sender (via XMPP).</li> </ol> <p>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 but 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…</p> <blockquote> <p>Do I need to write a rake task to start / stop / reload the bot</p> </blockquote> <p>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 some other tasks around the bot than just running it (some cleaning up, deployment, etc.), it will be good to use Rake for convenience. If not already, refactor bot's logic to class and use Rake task to initialize it. But it will probably be fine if you leave it and just run your script as is (using monit, your custom init.d script, ad-hoc, etc.).</p> <blockquote> <p>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 ?</p> </blockquote> <p>Rake doesn't have affect on this. From OS perspective, if you run Resque via Rake and your bot via Rake or as a standalone script, it doesn't matter, they will be different processes anyway. Also keep in mind that Resque needs Redis to be running somewhere.</p> <blockquote> <p>I know these might be very trivial questions</p> </blockquote> <p>No at all. I think it'll take some time before issues like could be considered trivial.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload