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
Spelling 101: it's acquire not aquire
Tobias Lütke (author)
2 months ago
commit  835469ed48f4c2de95856fe2f221eaa624b267a2
tree    1be46f9e8af60e12304e378ffae04e891b7557cf
parent  ef1e9941feb2788d6a4580bd7e033aaefad2cd73
...
1
2
3
4
 
5
6
 
7
8
9
...
11
12
13
14
 
15
16
17
...
23
24
25
26
27
 
28
...
1
2
3
 
4
5
 
6
7
8
9
...
11
12
13
 
14
15
16
17
...
23
24
25
 
26
27
28
0
@@ -1,9 +1,9 @@
0
 Locking
0
 =======
0
 
0
-Very simple plugin which adds the aquire_lock method to active record base. This is mysql only.
0
+Very simple plugin which adds the acquire_lock method to active record base. This is mysql only.
0
 
0
-As long as a lock of a certain name is acquired no other connection on the server is able to aquire the same lock.
0
+As long as a lock of a certain name is acquired no other connection on the server is able to acquire the same lock.
0
 This is very useful for background tasks such as billing or search server re-indexing which would cause errors when they
0
 would be ran from multiple machines at the same time but you still want to run them from multiple machines at the same time
0
 for redundancy reasons.
0
@@ -11,7 +11,7 @@ for redundancy reasons.
0
 Example
0
 =======
0
                                                                                                                               
0
-Invoice.aquire_lock("Shopify billing") do
0
+Invoice.acquire_lock("Shopify billing") do
0
 
0
   Invoice.find_all_due.each { |invoice| invoice.collect_payment! }
0
   
0
@@ -23,4 +23,4 @@ Usecase
0
                     
0
 # save to run on several machines at the same time:
0
  
0
- ./script/runner 'Invoice.aquire_lock("Shopify billing") { Invoice.find_all_due.each { |invoice| invoice.collect_payment! } }'
0
\ No newline at end of file
0
+ ./script/runner 'Invoice.acquire_lock("Shopify billing") { Invoice.find_all_due.each { |invoice| invoice.collect_payment! } }'
0
\ No newline at end of file
...
11
12
13
14
15
 
 
16
17
18
...
28
29
30
31
32
33
34
 
 
 
 
35
36
37
...
11
12
13
 
 
14
15
16
17
18
...
28
29
30
 
 
 
 
31
32
33
34
35
36
37
0
@@ -11,8 +11,8 @@ module Locking
0
     
0
   module ClassMethods
0
     
0
- # Aquires an application level lock in the mysql server.
0
- def aquire_lock(lock_name = table_name, wait_timeout = 0)
0
+ # acquires an application level lock in the mysql server.
0
+ def acquire_lock(lock_name = table_name, wait_timeout = 0)
0
       case c = connection.select_value("SELECT GET_LOCK(#{quote_value(lock_name)}, #{quote_value(wait_timeout)})")
0
       when '1'
0
         yield if block_given?
0
@@ -28,10 +28,10 @@ module Locking
0
       connection.select_one("SELECT RELEASE_LOCK(#{quote_value(lock_name)})")
0
     end
0
     
0
- # Aquires an application level lock in the mysql server. Throws Locking::LockTimeout if the
0
- # lock cannot be aquired.
0
- def aquire_lock!(lock_name = table_name, wait_timeout = 0, &block)
0
- aquire_lock(lock_name, table_name, &block) or raise LockTimeout, 'Timeout waiting for lock'
0
+ # acquires an application level lock in the mysql server. Throws Locking::LockTimeout if the
0
+ # lock cannot be acquired.
0
+ def acquire_lock!(lock_name = table_name, wait_timeout = 0, &block)
0
+ acquire_lock(lock_name, table_name, &block) or raise LockTimeout, 'Timeout waiting for lock'
0
     end
0
     
0
   end

Comments

    No one has commented yet.