morlock 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -2
- data/lib/morlock/base.rb +8 -1
- data/lib/morlock/gem_client.rb +5 -5
- data/lib/morlock/rails.rb +2 -1
- data/lib/morlock/version.rb +1 -1
- metadata +17 -7
data/README.markdown
CHANGED
@@ -28,7 +28,7 @@ With Bundler:
|
|
28
28
|
|
29
29
|
gem 'morlock', :require => 'morlock/rails'
|
30
30
|
|
31
|
-
Or in any script
|
31
|
+
Or in any script:
|
32
32
|
|
33
33
|
require 'morlock/rails'
|
34
34
|
|
@@ -41,7 +41,7 @@ Possible usages:
|
|
41
41
|
handle_failed_lock unless morlock.lock(key) do
|
42
42
|
# We have the lock
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
morlock.lock(key) { # We have the lock } || raise "Unable to lock!"
|
46
46
|
|
47
47
|
morlock.lock(key, :failure => failure_proc) do
|
@@ -49,3 +49,5 @@ Possible usages:
|
|
49
49
|
end
|
50
50
|
|
51
51
|
morlock.lock(key, :failure => failure_proc, :success => success_proc)
|
52
|
+
|
53
|
+
Morlock doesn't currently do retries, but this could be added in the future. Feel free to submit a patch!
|
data/lib/morlock/base.rb
CHANGED
@@ -11,11 +11,18 @@ class Morlock
|
|
11
11
|
|
12
12
|
def lock(key, options = {})
|
13
13
|
lock_obtained = @client.add(key, options[:expiration] || DEFAULT_EXPIRATION)
|
14
|
+
puts "Lock for #{key} #{lock_obtained ? "obtained" : "not obtained"}." if options[:verbose]
|
14
15
|
yield if lock_obtained && block_given?
|
15
16
|
options[:success].call if lock_obtained && options[:success]
|
16
17
|
options[:failure].call if !lock_obtained && options[:failure]
|
17
18
|
lock_obtained
|
18
19
|
ensure
|
19
|
-
|
20
|
+
if lock_obtained
|
21
|
+
if @client.delete(key)
|
22
|
+
puts "Lock removed for #{key}" if options[:verbose]
|
23
|
+
else
|
24
|
+
puts "Someone else removed the lock for #{key}!" if options[:verbose]
|
25
|
+
end
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/morlock/gem_client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Morlock
|
2
|
-
class UnknownGemClient < StandardError;
|
3
|
-
|
2
|
+
class UnknownGemClient < StandardError; end
|
3
|
+
|
4
4
|
|
5
5
|
class GemClient
|
6
6
|
GEM_CLIENTS = []
|
@@ -18,16 +18,16 @@ class Morlock
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
raise UnknownGemClient.new("You provided Morlock a memcached client of an unknown type: #{client.class}")
|
21
|
+
raise UnknownGemClient.new("You provided Morlock with a memcached client of an unknown type: #{client.class}")
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
24
|
def no_server_error(e)
|
26
|
-
STDERR.puts "WARNING: No memcached server found; Memlock was unable to create a lock. (#{e.message})"
|
25
|
+
STDERR.puts "WARNING: No memcached server was found; Memlock was unable to create a lock. (#{e.message})"
|
27
26
|
true
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
30
|
+
|
31
31
|
class DalliGemClient < GemClient
|
32
32
|
def add(key, expiration)
|
33
33
|
@client.add(key, 1, expiration)
|
data/lib/morlock/rails.rb
CHANGED
@@ -12,6 +12,8 @@ class Morlock
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
+
else
|
16
|
+
Rails.logger.warn "WARNING: Morlock could not load @data in #setup_for_mem_cache_store. Perhaps we don't yet work with this version of Rails?"
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -39,7 +41,6 @@ class Morlock
|
|
39
41
|
else
|
40
42
|
Rails.logger.warn "WARNING: Morlock detected that you are not using the Rails ActiveSupport::Cache::MemCacheStore. Rails.morlock will not be setup."
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
44
45
|
|
45
46
|
config.after_initialize do
|
data/lib/morlock/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rr
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: ''
|
37
47
|
email:
|
38
48
|
- pair+andrew+chris@mavenlink.com
|
@@ -74,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
84
|
version: '0'
|
75
85
|
requirements: []
|
76
86
|
rubyforge_project: morlock
|
77
|
-
rubygems_version: 1.8.
|
87
|
+
rubygems_version: 1.8.24
|
78
88
|
signing_key:
|
79
89
|
specification_version: 3
|
80
90
|
summary: Distributed locking with memcached.
|