mega_mutex 0.3.0 → 0.3.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.
- data/VERSION +1 -1
- data/lib/mega_mutex/distributed_mutex.rb +9 -3
- data/mega_mutex.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'logging'
|
2
2
|
require 'memcache'
|
3
|
+
require 'retryable'
|
3
4
|
|
4
5
|
module MegaMutex
|
5
6
|
class TimeoutError < Exception; end
|
6
7
|
|
7
8
|
class DistributedMutex
|
9
|
+
include Retryable
|
8
10
|
|
9
11
|
class << self
|
10
12
|
def cache
|
@@ -53,8 +55,10 @@ module MegaMutex
|
|
53
55
|
|
54
56
|
def lock!
|
55
57
|
until timeout?
|
56
|
-
|
57
|
-
|
58
|
+
retryable(:tries => 5, :sleep => 30, :on => MemCache::MemCacheError, :matching => /IO timeout/) do
|
59
|
+
return if attempt_to_lock == my_lock_id
|
60
|
+
sleep 0.1
|
61
|
+
end
|
58
62
|
end
|
59
63
|
raise TimeoutError.new("Failed to obtain a lock within #{@timeout} seconds.")
|
60
64
|
end
|
@@ -67,7 +71,9 @@ module MegaMutex
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def unlock!
|
70
|
-
|
74
|
+
retryable(:tries => 5, :sleep => 30, :on => MemCache::MemCacheError, :matching => /IO timeout/) do
|
75
|
+
cache.delete(@key) if locked_by_me?
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
def locked_by_me?
|
data/mega_mutex.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mega_mutex}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Johnson", "Matt Wynne"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-09-14}
|
13
13
|
s.description = %q{Distributed mutex for Ruby}
|
14
14
|
s.email = %q{developers@songkick.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mega_mutex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Johnson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2011-09-14 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|