public this repo is viewable by everyone
Description: Global named locks (req. mysql) -- Extraction from Shopify
Homepage: http://www.shopify.com
Clone URL: git://github.com/tobi/locking.git
Tobias Lütke (author)
2 months ago
commit  835469ed48f4c2de95856fe2f221eaa624b267a2
tree    1be46f9e8af60e12304e378ffae04e891b7557cf
parent  ef1e9941feb2788d6a4580bd7e033aaefad2cd73
name age message
folder README Sat Mar 08 10:32:56 -0800 2008 Spelling 101: it's acquire not aquire [Tobias Lütke]
folder init.rb Wed Mar 05 15:17:24 -0800 2008 Initial git import [Tobias Lütke]
folder lib/ Sat Mar 08 10:32:56 -0800 2008 Spelling 101: it's acquire not aquire [Tobias Lütke]
README
Locking
=======

Very simple plugin which adds the acquire_lock method to active record base. This is mysql only.

As long as a lock of a certain name is acquired no other connection on the server is able to acquire the same lock. 
This is very useful for background tasks such as billing or search server re-indexing which would cause errors when they 

would be ran from multiple machines at the same time but you still want to run them from multiple machines at the same 
time 
for redundancy reasons. 

Example
=======
                                                                                                                         
                                                                                                                               
Invoice.acquire_lock("Shopify billing") do

  Invoice.find_all_due.each { |invoice| invoice.collect_payment! } 
  
end


Usecase
=======
                    
# save to run on several machines at the same time: 
 
 ./script/runner 'Invoice.acquire_lock("Shopify billing") {  Invoice.find_all_due.each { |invoice| 
 invoice.collect_payment! } }'