zk_recipes 0.2.1 → 0.2.2

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: 37a0d167b23c76d73ecfb6255f77c636b31d5c48
4
- data.tar.gz: bd1e2e0f61651b90223f10eb792adcd8af83c801
3
+ metadata.gz: 8fa28d0852ec9e71d6f8a38daaf6c77626e11b7d
4
+ data.tar.gz: c2222216513454ecf137f88c266345327085551f
5
5
  SHA512:
6
- metadata.gz: 6d5a3ac3aa698cd69a166ed8690c2bae9648873ae76b8ea85142c15a2628ac56850f2a0c2c0f42d6dbd61b7282705cddd3e5151b4fada7136148a28866e843fe
7
- data.tar.gz: 3b17097bff56c25f5419171731e52245597ec79af4f6c694d531a7ab302dcecd452d49d86e426b7f4613e0bed332f4066ed11fc5ed49c2d6451b4e4154ba3d87
6
+ metadata.gz: 90599a5eb832a705ce159dcc88c1d1ca8bed88b9b282e3996b049d65a50acd3d0f6f77463a956899b19ac6deca389ab07a790c7ecf0e79b0d0adeda89a724b83
7
+ data.tar.gz: 247ca67c9cee03ab06da4e117908947ab7fc85dc598a930341b3d877534653b3a16c6bf901a266a73e32bdc3339fec42b7d3f40ce0a024155e4e4cf4e8898e3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2
4
+
5
+ - More logging tweaks: use block form of logging for everything *execpt* string literals
6
+ - Add `ZkRecipes::Cache::USE_DEFAULT` marker so deserializers can return a default value without raising
7
+
3
8
  ## 0.2.1
4
9
 
5
10
  - Tweak logging
@@ -55,13 +55,13 @@ module ZkRecipes
55
55
  @registered_values.each do |path, _value|
56
56
  @watches[path] = @zk.register(path) do |event|
57
57
  if event.node_event?
58
- debug("node event path=#{event.path} #{event.event_name} #{event.state_name}")
58
+ debug { "node event path=#{event.path} #{event.event_name} #{event.state_name}" }
59
59
  unless update_cache(event.path)
60
60
  @pending_updates[path] = nil
61
61
  @zk.defer { process_pending_updates }
62
62
  end
63
63
  else
64
- warn("session event #{event.event_name} #{event.state_name}")
64
+ warn { "session event #{event.event_name} #{event.state_name}" }
65
65
  end
66
66
  end
67
67
  end
@@ -82,16 +82,16 @@ module ZkRecipes
82
82
  end
83
83
 
84
84
  @zk.on_exception do |e|
85
- error("on_exception exception=#{e.inspect} backtrace=#{e.backtrace.inspect}")
85
+ error { "on_exception exception=#{e.inspect} backtrace=#{e.backtrace.inspect}" }
86
86
  end
87
87
  end
88
88
 
89
89
  def wait_for_warm_cache(timeout = 30)
90
- debug("waiting for cache to warm timeout=#{timeout.inspect}")
90
+ debug { "waiting for cache to warm timeout=#{timeout.inspect}" }
91
91
  if @latch.wait(timeout)
92
92
  true
93
93
  else
94
- warn("didn't warm cache before timeout connected=#{@zk.connected?} timeout=#{timeout.inspect}")
94
+ warn { "didn't warm cache before timeout connected=#{@zk.connected?} timeout=#{timeout.inspect}" }
95
95
  false
96
96
  end
97
97
  end
@@ -135,7 +135,7 @@ module ZkRecipes
135
135
  def connect(host, zk_opts)
136
136
  raise Error, "already connected" if @zk
137
137
 
138
- debug("connecting host=#{host.inspect}")
138
+ debug { "connecting host=#{host.inspect}" }
139
139
  ZK.new(host, **zk_opts) do |zk|
140
140
  setup_callbacks(zk)
141
141
  end
@@ -150,7 +150,7 @@ module ZkRecipes
150
150
  unless stat.exists?
151
151
  value = @registered_values.fetch(path).default_value
152
152
  @cache[path] = CachedPath.new(value, stat: stat)
153
- debug("no node, setting watch path=#{path}")
153
+ debug { "no node, setting watch path=#{path}" }
154
154
  instrument_params[:value] = value
155
155
  ActiveSupport::Notifications.instrument(AS_NOTIFICATION, instrument_params)
156
156
  return true
@@ -167,29 +167,34 @@ module ZkRecipes
167
167
  registered_value = @registered_values.fetch(path)
168
168
  instrument_params[:value] = registered_value.deserialize(raw_value)
169
169
  rescue => e
170
- error("deserialization error path=#{path} stat=#{stat.inspect} exception=#{e.inspect} #{e.backtrace.inspect}")
170
+ error { "deserialization error path=#{path} stat=#{stat.inspect} exception=#{e.inspect} #{e.backtrace.inspect}" }
171
171
  instrument_params[:error] = e
172
172
  instrument_params[:raw_value] = raw_value
173
173
  valid = false
174
174
  registered_value.default_value
175
175
  end
176
176
 
177
+ if value == USE_DEFAULT
178
+ valid = false
179
+ value = registered_value.default_value
180
+ end
181
+
177
182
  @cache[path] = CachedPath.new(value, stat: stat, valid: valid)
178
183
 
179
184
  ActiveSupport::Notifications.instrument(AS_NOTIFICATION, instrument_params)
180
185
  debug { "update_cache path=#{path} raw_value=#{raw_value.inspect} value=#{value.inspect} stat=#{stat.inspect}" }
181
186
  true
182
187
  rescue ::ZK::Exceptions::ZKError => e
183
- warn("update_cache path=#{path} exception=#{e.inspect}, retrying")
188
+ warn { "update_cache path=#{path} exception=#{e.inspect}, retrying" }
184
189
  retry
185
190
  rescue ::ZK::Exceptions::KeeperException, ::Zookeeper::Exceptions::ZookeeperException => e
186
- error("update_cache path=#{path} exception=#{e.inspect}")
191
+ error { "update_cache path=#{path} exception=#{e.inspect}" }
187
192
  false
188
193
  end
189
194
 
190
195
  def process_pending_updates
191
196
  return if @pending_updates.empty?
192
- debug("processing pending updates=#{@pending_updates.size}")
197
+ debug { "processing pending updates=#{@pending_updates.size}" }
193
198
  @pending_updates.reject! do |missed_path, _|
194
199
  update_cache(missed_path)
195
200
  end
@@ -204,6 +209,8 @@ module ZkRecipes
204
209
  EOM
205
210
  end
206
211
 
212
+ USE_DEFAULT = Object.new
213
+
207
214
  class CachedPath
208
215
  attr_reader :value, :stat
209
216
  def initialize(value, stat: nil, valid: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZkRecipes
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zk_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Lazarus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.6.11
96
+ rubygems_version: 2.6.13
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Common Recipes for Zookeeper