lock_manager 0.1.1 → 0.1.3
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 +13 -5
- data/README.md +2 -0
- data/lib/lock_manager/connection.rb +4 -4
- data/lib/lock_manager/redis_connection.rb +1 -1
- data/lib/lock_manager/worker.rb +9 -10
- data/lib/lock_manager.rb +1 -1
- data/test/test_helper.rb +4 -0
- data/test/test_poll.rb +8 -1
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWUzNGQ5YjE1YjViMmUzYjBiOTgzMWNkZjg5OTcxNDc1NjNmM2Q5MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGY2NTY2ZTNmZTRiMjU1ZjM5MmNlOWJhZjc5NmY5NWFlMzZjOGQyMQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTUzNGI1YTg4YzFmMzA0MzFkZGFhMjczNzM2NjEwYmY5OGFhYjMyOTI1NmRh
|
10
|
+
MzU4ZGFmOTYxMjdiZWUxNWU5OWViYzM0YmJlMDk4YmY3ODMzOTRhNjVmNTcz
|
11
|
+
Mjc0MWI1M2I3NDkzZTJmOTM2ZjMzNmJkMTI2NTE4NWE2ZDhlNzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjYyNTMyNWFlNTE3ZDkxZTJmYjUyNWU2NjQwMzAwMWU0ZTY2MDUwNjJlM2Nh
|
14
|
+
NmM1MjBkMWUzOGI0MjA4ZWMzMjBiODIyMjJjNmM0OTc0ZjYyOWY0ZmU4Yzg5
|
15
|
+
NzBhZjFlOWIxMDIxOTVlZDFiY2QzOWU2MDhhYmM4ZWNiZmYyODg=
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Lock Manager
|
2
2
|
|
3
|
+
[](https://travis-ci.org/puppetlabs/lock_manager)
|
4
|
+
|
3
5
|
Lock manager is designed to be a small helper gem that provides common methods
|
4
6
|
for locking and unlocking hardware.
|
5
7
|
|
@@ -8,7 +8,7 @@ class LockManager
|
|
8
8
|
require 'lock_manager/redis_connection'
|
9
9
|
LockManager::RedisConnection
|
10
10
|
else
|
11
|
-
|
11
|
+
raise ArgumentError, "Unknown connection type: #{type}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,15 +17,15 @@ class LockManager
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def write(key, value)
|
20
|
-
|
20
|
+
raise "Not implemented: write(#{key}, #{value})"
|
21
21
|
end
|
22
22
|
|
23
23
|
def read(key)
|
24
|
-
|
24
|
+
raise "Not implemented: read(#{key})"
|
25
25
|
end
|
26
26
|
|
27
27
|
def remove(key)
|
28
|
-
|
28
|
+
raise "Not implemented: remove(#{key})"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -6,7 +6,7 @@ class LockManager
|
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
8
|
super
|
9
|
-
|
9
|
+
raise ArgumentError, ':server option is mandatory for redis connections' unless options[:server]
|
10
10
|
@server = options[:server]
|
11
11
|
@port = options[:port]
|
12
12
|
end
|
data/lib/lock_manager/worker.rb
CHANGED
@@ -7,7 +7,7 @@ class LockManager
|
|
7
7
|
def initialize(connection, host)
|
8
8
|
@connection = connection
|
9
9
|
if host =~ Regexp.union(Resolv::IPv4::Regex, Resolv::IPv6::Regex)
|
10
|
-
|
10
|
+
raise ArgumentError, 'Please use a DNS name rather than an IP address.'
|
11
11
|
else
|
12
12
|
# Using the shortname of the host has the downside of being unable to
|
13
13
|
# lock two hosts with the same shortname and different domains.
|
@@ -70,17 +70,16 @@ class LockManager
|
|
70
70
|
result['user']
|
71
71
|
end
|
72
72
|
|
73
|
-
def polling_lock(user, reason = nil)
|
73
|
+
def polling_lock(user, reason = nil, max_sleep = 600)
|
74
74
|
sleep_duration = 1
|
75
|
+
return lock(user, reason) unless locked?
|
75
76
|
loop do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
break
|
83
|
-
end
|
77
|
+
log "#{host} is locked..."
|
78
|
+
log "waiting #{sleep_duration} seconds."
|
79
|
+
sleep sleep_duration
|
80
|
+
sleep_duration *= 2
|
81
|
+
sleep_duration = max_sleep if sleep_duration > max_sleep
|
82
|
+
break unless locked?
|
84
83
|
end
|
85
84
|
lock(user, reason)
|
86
85
|
end
|
data/lib/lock_manager.rb
CHANGED
@@ -30,7 +30,7 @@ class LockManager
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def connection
|
33
|
-
|
33
|
+
raise ArgumentError, ':type option is required' unless options[:type]
|
34
34
|
@connection ||= LockManager::Connection.connection_class(options[:type]).new(options)
|
35
35
|
end
|
36
36
|
end
|
data/test/test_helper.rb
CHANGED
data/test/test_poll.rb
CHANGED
@@ -11,6 +11,13 @@ class TestLockManagerPoll < MiniTest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_polling_lock_when_locked_already
|
14
|
-
|
14
|
+
assert_raises Timeout::Error do
|
15
|
+
Timeout.timeout(3) do
|
16
|
+
@rlm.lock('pe-aix-72-builder', 'stahnma')
|
17
|
+
@rlm.polling_lock('pe-aix-72-builder', 'stahnma')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
assert @rlm.locked?('pe-aix-72-builder')
|
15
22
|
end
|
16
23
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lock_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.8'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: redis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
55
|
description: A simple interface for locking hardware resources available via ruby
|
@@ -81,24 +81,25 @@ require_paths:
|
|
81
81
|
- lib
|
82
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- -
|
84
|
+
- - ! '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: 1.9.3
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.4.
|
94
|
+
rubygems_version: 2.4.6
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: Simply system for locking and unlocking hardware resources.
|
98
98
|
test_files:
|
99
|
-
- test/test_redis_connect.rb
|
100
|
-
- test/test_unlock.rb
|
101
|
-
- test/test_show.rb
|
102
99
|
- test/test_lock.rb
|
103
|
-
- test/
|
100
|
+
- test/test_show.rb
|
104
101
|
- test/test_poll.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
- test/test_unlock.rb
|
104
|
+
- test/test_redis_connect.rb
|
105
|
+
has_rdoc:
|