Backgroundrb is pretty cool stuff
For my employer I'm developing a rails app that needs to do a lot of RPC calls in the background. It's not really putting strain on our servers, but that sort of stuff will always take longer than you want it to. At first I just wanted PHP-style output buffering. However that doesn't scale too well with rails setups being the way they are.
To improve stability and reliability, we need to seperate it from the rails environment copmletely.
Enter Backgroundrb.
Backgroundrb lets you do some heavy lifting in the background. It's basically a separate server that allows you to run worker threads.
Now you might ask: "How does this fit into rails?". Well, it goes a little something like this...
The worker (put this in /lib/workers)
class ExampleWorker < BackgrounDRb::Worker::RailsBase
def do_work(args)
results[:some_string] = "I'm robust!"
end
end
ExampleWorker.registerRequest for heavy lifting coming in:
def background_action
session[:job_key] = MiddleMan.new_worker(:class => :example_worker, :args => {:arg => params[:some_arg]})
endResponse going out (this could be used in an AJAX calback action):
def callback
@result = MiddleMan.worker(session[:job_key]).results[:some_string]
end
It's so simple I couldn't have thought it up!
You can name your worker jobs by passing :job_key in the :args hash.
Let me speculate that this will become a widely used plugin as rails is receiving more and more commercial adoption. Who knows, it might even get merged into rails core! It definetly blows PHP's output buffering out of the water!
Trackbacks
Use the following link to trackback from your own site:
http://blog.aczid.nl/trackbacks?article_id=4










