On 4/26/06 3:38 PM, “Alex W.” firstname.lastname@example.org wrote:
I’ll see if mongrel can tickle my fancy.
Sorry Alex, not matter what Rails has to get locked. If you have very
running processes and need to give updated status, there’s a pattern you
should probably look into. Basically, you offload the real work to a
server (they’re trivial to write). The DRb server then gives you status
the job which you report via Ajax. When the work is done you collect
result from the DRb server and display it.
Here’s a basic kind of pseudo code (which I’ve got to write up soon):
worker = WorkerClient.new(host, port) # you write this client with
ticket = worker.dowork(“blah”)
session[:ticket] = ticket
worker = WorkerClient.new(host, port)
render :partial => “worker_done”
render :partial => “worker_not_done”
results = worker.get_results(session[:ticket])
None of that will work out of the box, just kind of there to give you an
idea. WorkerClient would be a simple DRb client that you’d connect to a
server that receives work commands. DRb is ultra easy so don’t be
In setup_work you get the worker to dowork and it returns a little
(probably just a simple integer ID) that you can use later to poll for
You browser then uses some nifty ajax to hit the
All this action does is fire up a WorkerClient and ask the worker if the
with the given ticket is done yet. When it’s not you return the right
partial to keep the ajax going. If it is you return the partial that
the ajax progress go to the work_done action.
At the work_done action you simply take the ticket and get the results.
There’s about a billion variants of this technique, but the idea is that
setup_work action gets out right away, the work is offloaded to another
server to do the waiting and crunching, and the results are collected
This keeps your Rails nice and snappy.
But, the real benefit of this is that you can actually move all of
code out to a snazzy ultra fast Mongrel handler and not even use Rails.
might have to use rails in the setup_worker and most definitely in
work_done, but in the ajaxy_worker_done_check it would only be using DRb
no need to hook up rails. Only change you’d have to make is to pass the
ticket in via a Mongrel Handler’s request params rather than using the
session (which also makes this stateless).
Well, good luck.
Zed A. Shaw