sdb_lock 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sdb_lock.rb +6 -4
- data/lib/sdb_lock/version.rb +1 -1
- data/test/test_lock.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5e7a44b667ffa0738e16fa2f8ecc5be2b43c085
|
4
|
+
data.tar.gz: 4e30eedc8fdbd10920711b802f731c0ba54eb7e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3504f3056d664a84d3b3eb6003e5e926f968c369b7f4def347b1df5f1357179f586c74f9bf8d7c7d5aa94b28728ae5f5099f4f6d4c9ed5cca5b7dbaa43e22b60
|
7
|
+
data.tar.gz: 518a2590612a46f21c41533c75bda96b07a387b3af3f848df3b03cd5b65d3dbc0027e623569ebe187afa7c3befb53d47a6e6757df66a86a318fa1f5f73968b5e
|
data/lib/sdb_lock.rb
CHANGED
@@ -45,14 +45,15 @@ class SdbLock
|
|
45
45
|
# Try to lock resource_name
|
46
46
|
#
|
47
47
|
# @param [String] resource_name name to lock
|
48
|
+
# @param [Array] additional_attributes include additional attributes
|
48
49
|
# @return [TrueClass] true when locked, unless false
|
49
|
-
def try_lock(resource_name)
|
50
|
+
def try_lock(resource_name, additional_attributes = [])
|
50
51
|
attributes = [
|
51
52
|
{
|
52
53
|
name: LOCK_TIME,
|
53
54
|
value: format_time(Time.now)
|
54
55
|
}
|
55
|
-
]
|
56
|
+
].concat(additional_attributes)
|
56
57
|
|
57
58
|
@sdb.put_attributes(
|
58
59
|
domain_name: @domain_name,
|
@@ -79,10 +80,11 @@ class SdbLock
|
|
79
80
|
# It blocks until lock is succeeded.
|
80
81
|
#
|
81
82
|
# @param [String] resource_name
|
82
|
-
|
83
|
+
# @param [Array] additional_attributes include additional attributes
|
84
|
+
def lock(resource_name, additional_attributes = [])
|
83
85
|
wait_secs = 0.5
|
84
86
|
while true
|
85
|
-
lock = try_lock(resource_name)
|
87
|
+
lock = try_lock(resource_name, additional_attributes)
|
86
88
|
break if lock
|
87
89
|
sleep([wait_secs, MAX_WAIT_SECS].min)
|
88
90
|
wait_secs *= 2
|
data/lib/sdb_lock/version.rb
CHANGED
data/test/test_lock.rb
CHANGED
@@ -36,4 +36,32 @@ class LockTest < MiniTest::Test
|
|
36
36
|
threads.each { |thread| thread.join }
|
37
37
|
assert_equal(10, shared_var)
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_additional_attributes
|
41
|
+
additional_attributes = [
|
42
|
+
{
|
43
|
+
name: 'additional_attribute',
|
44
|
+
value: 'test'
|
45
|
+
}
|
46
|
+
]
|
47
|
+
|
48
|
+
@lock.lock("test", additional_attributes)
|
49
|
+
# Checking the values of an attribute are not always immediately available,
|
50
|
+
# so sleep for a second.
|
51
|
+
sleep(1)
|
52
|
+
attributes = @lock.send(:item, "test")
|
53
|
+
value = attributes.each do |a|
|
54
|
+
break a.value if a.name == 'additional_attribute'
|
55
|
+
end
|
56
|
+
# Additional attributes were set
|
57
|
+
assert_equal('test', value)
|
58
|
+
|
59
|
+
@lock.unlock("test")
|
60
|
+
# Checking the values of an attribute are not always immediately available,
|
61
|
+
# so sleep for a second.
|
62
|
+
sleep(1)
|
63
|
+
attributes = @lock.send(:item, "test")
|
64
|
+
# Additional attributes were unset
|
65
|
+
assert_equal([], attributes)
|
66
|
+
end
|
39
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdb_lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KAWACHI Takashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|