lock_and_cache 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/lib/lock_and_cache.rb +2 -0
- data/lib/lock_and_cache/action.rb +8 -8
- data/lib/lock_and_cache/key.rb +1 -1
- data/lib/lock_and_cache/version.rb +1 -1
- data/spec/lock_and_cache_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f75de7ca663703123c5a93b4c03960ce20449e
|
4
|
+
data.tar.gz: e6f260e217549f32b4ce54b8e8fe03adbc27078e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a027a15e0ec3c8918f9825d57a97f059a93a91bf43d2aefd32d7cd0cedf6eb223fddfd0df006e652824e927573a6cba408bd4f22bbd2c2ce7fb1345377ca985
|
7
|
+
data.tar.gz: 4ebe3e917a13f182e04a5e10fc19c58d109db200e2ac42bb1cb4078c1122eda2bd331836a3540ff794ba4987f326d33a8792b974fd26c0ac27ad9312a23ff9ca
|
data/CHANGELOG
CHANGED
data/lib/lock_and_cache.rb
CHANGED
@@ -40,37 +40,37 @@ module LockAndCache
|
|
40
40
|
heartbeat_expires = options.fetch('heartbeat_expires', LockAndCache.heartbeat_expires).to_f.ceil
|
41
41
|
raise "heartbeat_expires must be >= 2 seconds" unless heartbeat_expires >= 2
|
42
42
|
heartbeat_frequency = (heartbeat_expires / 2).ceil
|
43
|
-
|
43
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] A1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
44
44
|
if storage.exists(digest) and (existing = storage.get(digest)).is_a?(String)
|
45
45
|
return ::Marshal.load(existing)
|
46
46
|
end
|
47
|
-
|
47
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] B1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
48
48
|
retval = nil
|
49
49
|
lock_manager = LockAndCache.lock_manager
|
50
50
|
lock_info = nil
|
51
51
|
begin
|
52
52
|
Timeout.timeout(max_lock_wait, TimeoutWaitingForLock) do
|
53
53
|
until lock_info = lock_manager.lock(lock_digest, heartbeat_expires*1000)
|
54
|
-
|
54
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] C1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
55
55
|
sleep rand
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] D1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
59
59
|
if storage.exists(digest) and (existing = storage.get(digest)).is_a?(String)
|
60
|
-
|
60
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] E1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
61
61
|
retval = ::Marshal.load existing
|
62
62
|
end
|
63
63
|
unless retval
|
64
|
-
|
64
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] F1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
65
65
|
done = false
|
66
66
|
begin
|
67
67
|
lock_extender = Thread.new do
|
68
68
|
loop do
|
69
|
-
|
69
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] heartbeat1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
70
70
|
break if done
|
71
71
|
sleep heartbeat_frequency
|
72
72
|
break if done
|
73
|
-
|
73
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] heartbeat2 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
|
74
74
|
lock_manager.lock lock_digest, heartbeat_expires*1000, extend: lock_info
|
75
75
|
end
|
76
76
|
end
|
data/lib/lock_and_cache/key.rb
CHANGED
@@ -75,7 +75,7 @@ module LockAndCache
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def clear
|
78
|
-
|
78
|
+
LockAndCache::LOG_MUTEX.synchronize { $stderr.puts "[lock_and_cache] clear #{debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if ENV['LOCK_AND_CACHE_DEBUG'] == 'true'
|
79
79
|
storage = LockAndCache.storage
|
80
80
|
storage.del digest
|
81
81
|
storage.del lock_digest
|
data/spec/lock_and_cache_spec.rb
CHANGED
@@ -91,7 +91,7 @@ class Bar
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def unsafe_click
|
94
|
-
|
94
|
+
LockAndCache::LOG_MUTEX.synchronize do
|
95
95
|
# puts "clicking bar #{@id} - #{$clicking.to_a} - #{$clicking.include?(@id)} - #{@id == $clicking.to_a[0]}"
|
96
96
|
raise "somebody already clicking Bar #{@id}" if $clicking.include?(@id)
|
97
97
|
$clicking << @id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lock_and_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|