ohm-contrib 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95ca2996cd69a1f85572aa47bd899c8a939498b5
4
- data.tar.gz: d71adacef87ae7cd37165afe78c900d2eb158c8b
3
+ metadata.gz: a52426f91b67c71d40fe30b9349b19523cc2ae49
4
+ data.tar.gz: b3e078c7c34c4f5936d1674317f71b6607c81f4e
5
5
  SHA512:
6
- metadata.gz: bac2979be97da13d457139c85309b45783b77e4d1520de1a95914e1db70587472468bfb190acd1c7172b5266e004af3e1c51aec0a799b3557b670293c8016857
7
- data.tar.gz: 5f900d67c1a7166970ae10bdc8042018bec1d60171acc9a8d1c40eaab27388a9b7d4dc7ba07fb7ce3d84de7f05709edc250289dc4c5c9af045e467cb16e6bc42
6
+ metadata.gz: 1bb1072d4f28ea0e59bb49cc0057e950f25cc831da0e4a12cc25b09ed613dba38e455efea60209cf8c8376d34f82afae804c909d437a1b6b83a01901441ead50
7
+ data.tar.gz: 5842bd888c672735b63919fd819e6bad5f8c75252c104664d445fe60728b7bcb49e2ed5fc8ba4fa6cf810dcdf9b554937c18249b96eef5d710cf259a7b651de7
@@ -12,10 +12,9 @@ module Ohm
12
12
  # post.mutex(0.01) do
13
13
  # # this block is in a mutex!
14
14
  # end
15
- def mutex(wait = 0.1)
15
+ def spinlock(wait = 0.1)
16
16
  lock!(wait)
17
17
  yield
18
- self
19
18
  ensure
20
19
  unlock!
21
20
  end
@@ -27,8 +26,8 @@ module Ohm
27
26
  #
28
27
  # @see Model#mutex
29
28
  def lock!(wait = 0.1)
30
- until redis.call("SETNX", key[:_lock], lock_timeout)
31
- next unless lock = redis.call("HGET", key[:_lock])
29
+ until redis.call("SETNX", key[:_lock], lock_timeout) == 1
30
+ next unless lock = redis.call("GET", key[:_lock])
32
31
  sleep(wait) and next unless lock_expired?(lock)
33
32
 
34
33
  break unless lock = redis.call("GETSET", key[:_lock], lock_timeout)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ohm-contrib"
3
- s.version = "2.0.0"
3
+ s.version = "2.0.1"
4
4
  s.summary = %{A collection of decoupled drop-in modules for Ohm.}
5
5
  s.description = %{Includes a couple of core functions such as callbacks, timestamping, typecasting and lots of generic validation routines.}
6
6
  s.author = "Cyril David"
@@ -10,9 +10,9 @@ Gem::Specification.new do |s|
10
10
 
11
11
  s.files = `git ls-files`.split("\n")
12
12
 
13
- s.add_dependency "ohm", "~> 2.0.0"
13
+ s.add_dependency "ohm", "~> 2.0"
14
14
 
15
- s.add_development_dependency "cutest"
16
- s.add_development_dependency "iconv"
17
- s.add_development_dependency "override"
15
+ s.add_development_dependency "cutest", "~> 1.2"
16
+ s.add_development_dependency "iconv", "~> 1.0"
17
+ s.add_development_dependency "override", "~> 0.0"
18
18
  end
@@ -3,8 +3,40 @@ require_relative "../lib/ohm/locking"
3
3
 
4
4
  class Server < Ohm::Model
5
5
  include Ohm::Locking
6
+ extend Ohm::Locking
7
+
8
+ attribute :taken
9
+ index :taken
10
+
11
+ def self.acquire
12
+ spinlock do
13
+ s = Server.find(taken: 0).first
14
+
15
+ if s
16
+ s.update(taken: 1)
17
+ end
18
+
19
+ return s
20
+ end
21
+ end
6
22
  end
7
23
 
8
24
  test "mutex method is added at instance and class level" do
9
- assert Server.new.respond_to?(:mutex)
25
+ assert Server.new.respond_to?(:spinlock)
26
+ end
27
+
28
+ test "acquire with concurrency" do
29
+ s = Server.create(taken: 0)
30
+
31
+ res = {}
32
+
33
+ threads = 5.times.map do |i|
34
+ Thread.new(i, res) do |idx, e|
35
+ e[idx] = Server.acquire
36
+ end
37
+ end
38
+
39
+ threads.each(&:join)
40
+
41
+ assert_equal 1, res.values.compact.size
10
42
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ohm
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cutest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.2'
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
- version: '0'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: iconv
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: override
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.0'
69
69
  description: Includes a couple of core functions such as callbacks, timestamping,
70
70
  typecasting and lots of generic validation routines.
71
71
  email: cyx@cyx.is
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gems
77
- - .gitignore
76
+ - ".gems"
77
+ - ".gitignore"
78
78
  - CHANGELOG.md
79
79
  - LICENSE
80
80
  - README.markdown
@@ -109,17 +109,17 @@ require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - '>='
112
+ - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - '>='
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.0.14
122
+ rubygems_version: 2.2.2
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: A collection of decoupled drop-in modules for Ohm.