You are here: Browse Railsplugins Simplified Starling
Works with Starling 0.9.6 or edge. You can follow these steps to build it.
sudo gem install newgem eventmachine rails_analyzer_tools memcache-client
git clone git://github.com/anotherbritt/starling.git
cd starling && rake gem && cd pkg && sudo gem install starling-0.9.6.gem
From Blaine Cook repository ...
git clone git://github.com/blaine/starling.git
cd starling
gem build starling.spec
gem install -l starling-0.9.7.5.gem
Note: I don't know which is the master copy of starling and I'm waiting an email reply from the developers.
= InstallingInstall this Rails plugin as usual.
script/plugin install git://github.com/fesplugas/simplified_starling.git
After installing the plugin you’ll find configuration files for each Rails environment under config/starling.
You’ll also find a initializer called starling.rb under config/initializers that will connect your application to the starling server.
=== How it works?
With starling installed in your machine you can start/stop/restart the daemon by running.
$ rake simplified:starling:start
$ rake simplified:starling:stop
$ rake simplified:starling:restart
You can put anything into Starling, but after using Starling on a couple of projects I’ve seen I use always the same hash for storing the jobs. This will push into the queue the task test_rendering which belongs to a model.
You can even push a class task into the queue. This will push into the queue the task recalculate which belongs to a model.
To view queue stats …
$ rake simplified:starling:stats
Processed jobs are logged.
$ tail -f log/development_starling.log
$ tail -f log/production_starling.log
=== Log
Each time a job is pushed and popped to the queue is logged.
[Pushed job @ 2008-06-30 11:06:03] Dispatch order
[Popped job @ 2008-06-30 11:06:03] Dispatch order
If database connection goes down or dies after a few hours of inactivity you’ll see a WARNING message, if everything went as expected, database connection will be restored and job will be sent again to the queue.
[Pushed job @ 2008-06-30 11:06:42] Rebuild page 3
[WARNING] Database connection gone, reconnecting & retrying.
{:type=>"Order", :task=>"dispatch", :id=>nil}
[Pushed job @ 2008-06-30 11:06:44] Rebuild page 3 (R)
[Popped job @ 2008-06-30 11:06:44] Rebuild page 3
If the record you’re trying to process is removed from the database before the queue is processed you’ll see a warning on the logs.
[Pushed job @ 2008-06-30 11:06:50] Rebuild page 3
[WARNING] Page#3 gone from database.
=== Example 1
Push a newsletter job into starling.
def test_deliver Newsletter.find(params[:id]).push(‘test_rendering’) flash[:notice] = “Newsletter added to queue.” redirect_to :back end
def deliver Newsletter.find(params[:id]).push(‘deliver’) flash[:notice] = “Newsletter added to queue.” redirect_to :back end
end
def test_rendering ## # Your long-running task to deliver newsletter to test rendering # in diferent email readers. end
def deliver ## # Long running task to deliver newsletter … # end
end
=== Example 2
Confirm an order payment and push into starling an stock recalculation job.
def confirm @order = Order.find_by_token(params[:token]) @order.confirm_payment flash[:notice] = “Thanks for your purchase!” redirect_to :action => ‘thanks’ end
end
def confirm_payment OrderMailer.deliver_payment_confirmation(order) Stock.push(‘recalculate’) end
end
def self.recalculate ## # A long running operation … # end
end
== Acknowledgments
- Blaine Cook, Twitter Inc. for this nice queue system.
Copyright© 2008 Francesc Esplugas Marti, released under the MIT license
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly