lock_method 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -13
- data/lib/lock_method.rb +3 -3
- data/lib/lock_method/lock.rb +5 -5
- data/lib/lock_method/version.rb +1 -1
- data/test/helper.rb +6 -6
- data/test/shared_tests.rb +2 -2
- metadata +16 -15
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Lets you lock a method so that only one process can call it at a time. Defaults
|
|
6
6
|
|
7
7
|
== Real-world usage
|
8
8
|
|
9
|
-
In production use at {
|
9
|
+
In production use at {impact.brighterplanet.com}[http://impact.brighterplanet.com] and {data.brighterplanet.com}[http://data.brighterplanet.com].
|
10
10
|
|
11
11
|
== Example
|
12
12
|
|
@@ -20,8 +20,8 @@ In production use at {carbon.brighterplanet.com}[http://carbon.brighterplanet.co
|
|
20
20
|
lock_method :get_latest_entries
|
21
21
|
|
22
22
|
# used by lock_method to differentiate between instances
|
23
|
-
def
|
24
|
-
url
|
23
|
+
def as_lock
|
24
|
+
url
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -32,25 +32,21 @@ Then you can do
|
|
32
32
|
|
33
33
|
Just in case, you can clear them
|
34
34
|
|
35
|
-
my_blog.
|
35
|
+
my_blog.lock_method_clear :get_latest_entries
|
36
36
|
|
37
37
|
== Pays attention to method arguments
|
38
38
|
|
39
39
|
If you lock Foo.bar(*args), calling Foo.bar(:baz) will not lock out Foo.bar(:zoo).
|
40
40
|
|
41
|
-
== Defining #
|
41
|
+
== Defining #as_lock
|
42
42
|
|
43
|
-
If you want to lock instance methods, you should define <tt>#
|
43
|
+
If you want to lock instance methods, you should define <tt>#as_lock</tt> on those instances.
|
44
44
|
|
45
|
-
|
45
|
+
== Locking across hosts
|
46
46
|
|
47
|
-
|
47
|
+
If you want to lock across hosts, just use shared storage, like a remote Redis or memcached instance.
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
== Defining #method_lock_hash instead of #hash
|
52
|
-
|
53
|
-
If you don't want to modify #hash, you can use #method_lock_hash instead.
|
49
|
+
If you want to lock locally, but you're using shared storage, just get the hostname of the locking instance into the <tt>as_lock</tt>.
|
54
50
|
|
55
51
|
== Configuration (and supported cache clients)
|
56
52
|
|
data/lib/lock_method.rb
CHANGED
@@ -20,13 +20,13 @@ module LockMethod
|
|
20
20
|
Config.instance
|
21
21
|
end
|
22
22
|
|
23
|
-
# All Objects, including instances and Classes, get the <tt>#
|
23
|
+
# All Objects, including instances and Classes, get the <tt>#lock_method_clear</tt> method.
|
24
24
|
module InstanceMethods
|
25
25
|
# Clear the lock for a particular method.
|
26
26
|
#
|
27
27
|
# Example:
|
28
|
-
# my_blog.
|
29
|
-
def
|
28
|
+
# my_blog.lock_method_clear :get_latest_entries
|
29
|
+
def lock_method_clear(method_id)
|
30
30
|
lock = ::LockMethod::Lock.new self, method_id
|
31
31
|
lock.delete
|
32
32
|
end
|
data/lib/lock_method/lock.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'digest/
|
1
|
+
require 'digest/sha1'
|
2
2
|
module LockMethod
|
3
3
|
class Lock #:nodoc: all
|
4
4
|
class << self
|
@@ -41,12 +41,12 @@ module LockMethod
|
|
41
41
|
@ttl ||= Config.instance.default_ttl
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
@
|
44
|
+
def obj_digest
|
45
|
+
@obj_digest ||= ::Digest::SHA1.hexdigest(::Marshal.dump(obj.respond_to?(:as_lock) ? obj.as_lock : obj))
|
46
46
|
end
|
47
47
|
|
48
48
|
def args_digest
|
49
|
-
@args_digest ||= args.to_a.empty? ? 'empty' : ::Digest::
|
49
|
+
@args_digest ||= args.to_a.empty? ? 'empty' : ::Digest::SHA1.hexdigest(::Marshal.dump(args))
|
50
50
|
end
|
51
51
|
|
52
52
|
def delete
|
@@ -65,7 +65,7 @@ module LockMethod
|
|
65
65
|
if obj.is_a?(::Class) or obj.is_a?(::Module)
|
66
66
|
[ 'LockMethod', 'Lock', method_signature, args_digest ].join ','
|
67
67
|
else
|
68
|
-
[ 'LockMethod', 'Lock', method_signature,
|
68
|
+
[ 'LockMethod', 'Lock', method_signature, obj_digest, args_digest ].join ','
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
data/lib/lock_method/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -25,17 +25,17 @@ class Blog1
|
|
25
25
|
["voo vaa #{name}"]
|
26
26
|
end
|
27
27
|
lock_method :get_latest_entries2, 5 # second
|
28
|
-
def
|
29
|
-
raise "Used
|
28
|
+
def marshal_dump
|
29
|
+
raise "Used marshal_dump"
|
30
30
|
end
|
31
|
-
def
|
32
|
-
name
|
31
|
+
def as_lock
|
32
|
+
name
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
class Blog1a < Blog1
|
37
|
-
def
|
38
|
-
raise "Used
|
37
|
+
def as_lock
|
38
|
+
raise "Used as_lock"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
data/test/shared_tests.rb
CHANGED
@@ -114,7 +114,7 @@ module SharedTests
|
|
114
114
|
end
|
115
115
|
|
116
116
|
# but now we clear the lock
|
117
|
-
new_instance_of_my_blog.
|
117
|
+
new_instance_of_my_blog.lock_method_clear :get_latest_entries
|
118
118
|
assert_nothing_raised do
|
119
119
|
new_instance_of_my_blog.get_latest_entries
|
120
120
|
end
|
@@ -134,7 +134,7 @@ module SharedTests
|
|
134
134
|
end
|
135
135
|
|
136
136
|
# but now we clear the lock
|
137
|
-
Blog2.
|
137
|
+
Blog2.lock_method_clear :get_latest_entries
|
138
138
|
assert_nothing_raised do
|
139
139
|
Blog2.get_latest_entries
|
140
140
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lock_method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cache
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152246540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152246540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152240680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152240680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: test-unit
|
38
|
-
requirement: &
|
38
|
+
requirement: &2160094560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160094560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: memcached
|
49
|
-
requirement: &
|
49
|
+
requirement: &2160090340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2160090340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: redis
|
60
|
-
requirement: &
|
60
|
+
requirement: &2160103240 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2160103240
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ruby-debug19
|
71
|
-
requirement: &
|
71
|
+
requirement: &2160101140 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2160101140
|
80
80
|
description: Like alias_method, but it's lock_method!
|
81
81
|
email:
|
82
82
|
- seamus@abshere.net
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project: lock_method
|
122
|
-
rubygems_version: 1.8.
|
122
|
+
rubygems_version: 1.8.15
|
123
123
|
signing_key:
|
124
124
|
specification_version: 3
|
125
125
|
summary: Lets you lock methods (to memcached, redis, etc.) as though you had a lockfile
|
@@ -130,3 +130,4 @@ test_files:
|
|
130
130
|
- test/test_default_storage.rb
|
131
131
|
- test/test_memcached_storage.rb
|
132
132
|
- test/test_redis_storage.rb
|
133
|
+
has_rdoc:
|