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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90b85cb8a2f2d566cbf6cd7a69375ee6772206c8
4
- data.tar.gz: fae5041a751ce3617604de792c8f0cc6400919d2
3
+ metadata.gz: 49f75de7ca663703123c5a93b4c03960ce20449e
4
+ data.tar.gz: e6f260e217549f32b4ce54b8e8fe03adbc27078e
5
5
  SHA512:
6
- metadata.gz: b54fa87634f6e9378eec8ab209eed851a41bd1e13e5cc10af293b80d0d68b217cd46ddbf496cbe49e959ec6f6dc100f582201e8ca316940eb0b6ad2db8b880c5
7
- data.tar.gz: 1002dc77996ab481d8d150261cde2d7b8e9afc08640edad85ca5171ba7f6b5ac6d1dfcfbb249c956b67e13ef2813f48b88c04e69c07196cef84898e567800480
6
+ metadata.gz: 6a027a15e0ec3c8918f9825d57a97f059a93a91bf43d2aefd32d7cd0cedf6eb223fddfd0df006e652824e927573a6cba408bd4f22bbd2c2ce7fb1345377ca985
7
+ data.tar.gz: 4ebe3e917a13f182e04a5e10fc19c58d109db200e2ac42bb1cb4078c1122eda2bd331836a3540ff794ba4987f326d33a8792b974fd26c0ac27ad9312a23ff9ca
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 3.0.1 / 2016-04-04
2
+
3
+ * Enhancements
4
+
5
+ * Don't use deprecated Thread.exclusive
6
+
1
7
  3.0.0 / 2016-04-02
2
8
 
3
9
  * Breaking changes
@@ -18,6 +18,8 @@ module LockAndCache
18
18
 
19
19
  DEFAULT_HEARTBEAT_EXPIRES = 32 # 32 seconds
20
20
 
21
+ LOG_MUTEX = Mutex.new
22
+
21
23
  class TimeoutWaitingForLock < StandardError; end
22
24
 
23
25
  # @param redis_connection [Redis] A redis connection to be used for lock and cached value storage
@@ -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
- Thread.exclusive { $stderr.puts "[lock_and_cache] A1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] B1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] C1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] D1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] E1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] F1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] heartbeat1 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
- Thread.exclusive { $stderr.puts "[lock_and_cache] heartbeat2 #{key.debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if debug
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
@@ -75,7 +75,7 @@ module LockAndCache
75
75
  end
76
76
 
77
77
  def clear
78
- Thread.exclusive { $stderr.puts "[lock_and_cache] clear #{debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" } if ENV['LOCK_AND_CACHE_DEBUG'] == 'true'
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
@@ -1,3 +1,3 @@
1
1
  module LockAndCache
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -91,7 +91,7 @@ class Bar
91
91
  end
92
92
 
93
93
  def unsafe_click
94
- Thread.exclusive do
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.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-02 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport