public
Description: Global named locks (req. mysql) -- Extraction from Shopify
Homepage: http://www.shopify.com
Clone URL: git://github.com/tobi/locking.git
Search Repo:
Tobias Lütke (author)
Wed Mar 05 15:17:24 -0800 2008
commit  ef1e9941feb2788d6a4580bd7e033aaefad2cd73
tree    e2c02b89c229fdb16ba6d45f9e965ea9a3890504
locking / README
100644 26 lines (16 sloc) 0.985 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Locking
=======
 
Very simple plugin which adds the aquire_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 aquire 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.aquire_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.aquire_lock("Shopify billing") { Invoice.find_all_due.each { |invoice| invoice.collect_payment! } }'