lock_manager 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6182864c1d1e43eda6276e9459037dd7c0aaf176
4
- data.tar.gz: 6b6eb4cc2823147881e540080ddc930c2d942dcc
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWUzNGQ5YjE1YjViMmUzYjBiOTgzMWNkZjg5OTcxNDc1NjNmM2Q5MQ==
5
+ data.tar.gz: !binary |-
6
+ OGY2NTY2ZTNmZTRiMjU1ZjM5MmNlOWJhZjc5NmY5NWFlMzZjOGQyMQ==
5
7
  SHA512:
6
- metadata.gz: 9bdb3020bb25b41f471c102864f86a93eefb4948ccf204d19d16b155be91c4a84fbaa9deb53ac65be109fd4b3e1f918e446c091ce5ab3f9542f03b93e6767f6b
7
- data.tar.gz: 0fe35dfea4dd4c5768e32f665b9859ab89f7973bfb14d288fb5c04dd50db4a2a02b49aab49c15e12bb0b819f215d8b1c951de25f2ad5b1286fd5b1dd787d6577
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
+ [![Build Status](https://travis-ci.org/puppetlabs/lock_manager.svg?branch=master)](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
- fail ArgumentError, "Unknown connection type: #{type}"
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
- fail "Not implemented: write(#{key}, #{value})"
20
+ raise "Not implemented: write(#{key}, #{value})"
21
21
  end
22
22
 
23
23
  def read(key)
24
- fail "Not implemented: read(#{key})"
24
+ raise "Not implemented: read(#{key})"
25
25
  end
26
26
 
27
27
  def remove(key)
28
- fail "Not implemented: remove(#{key})"
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
- fail ArgumentError, ':server option is mandatory for redis connections' unless options[:server]
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
@@ -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
- fail ArgumentError, 'Please use a DNS name rather than an IP address.'
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
- if locked?
77
- log "#{host} is locked..."
78
- log "waiting #{sleep_duration} seconds."
79
- sleep sleep_duration
80
- sleep_duration *= 2
81
- else
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
- fail ArgumentError, ':type option is required' unless options[:type]
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
@@ -1,3 +1,7 @@
1
+
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+
1
5
  require 'minitest/autorun'
2
6
  require 'json'
3
7
  require 'lock_manager'
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
- skip "I don't know how to test the case where it is locked, since it just blocks"
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.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: 2015-12-17 00:00:00.000000000 Z
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: '2.1'
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.8
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/test_helper.rb
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: