bogo 0.1.28 → 0.1.30

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c174f6ad37a9e19f3dfe03122c33a495806dccb3
4
- data.tar.gz: 3912483719bc84e6af89542580c05dd45aaef600
3
+ metadata.gz: e2bc7e71e08bfe678b9ebe7ffd966ffca3092e43
4
+ data.tar.gz: ffd41d8ceee8a00c968342b87d32101fa1d58caf
5
5
  SHA512:
6
- metadata.gz: 0fac9b5a22d68c59244e2285812eb78eddab548692b61cae3bc249df04a9ea551a2392c99be411589b5bdbed39bc91118c10eedd7f761f8c80959ad22db88b3a
7
- data.tar.gz: b56a8eac111a44ad7d71eefa03cfdf79a8ff652f2b976e958da93d57faca47877cb1d9edc20df87157114c096d1842f5c9db14e830ddb539e9a7bc94a919f1f6
6
+ metadata.gz: db23673068170fd07463703a5709bdae78a9b0185d68cc52d77001c9791415a27a939a3dbf34b4a7893e631918e6797ae85d6c1aace3b5698a17deacad4896a2
7
+ data.tar.gz: a4ac702da3acf7702440a8625fc5366834108acee91820a162bd491d0ae74d8e49fdf56a589c5d02e51d8946bf3847ad15e711b835609185a6ed2557cc472e71
@@ -1,3 +1,7 @@
1
+ ## v0.1.30
2
+ * [Lazy] Inspect data prior to checksum to prevent circular issues
3
+ * [Retry] Support custom block to determine retry
4
+
1
5
  ## v0.1.28
2
6
  * [Smash] Ensure valid data type on checksum generation
3
7
  * [Retry] Add new retry abstract and concrete subclasses
data/README.md CHANGED
@@ -310,5 +310,71 @@ e_file.close
310
310
  puts "File exists: #{File.exists?(path)}"
311
311
  ```
312
312
 
313
+ ## Retry
314
+
315
+ Retry an action until success or maximum number of attempts
316
+ has been reached.
317
+
318
+ ### `Bogo::Retry`
319
+
320
+ This is an abstract class and does not provide actual retry
321
+ functionality. Custom concrete implementations must define a
322
+ `#wait_on_failure` method that provides the number of seconds
323
+ to wait until the next attempt.
324
+
325
+ The `Bogo::Retry` does provide an easy way to generate a
326
+ retry instance:
327
+
328
+ ```ruby
329
+ Bogo::Retry.build(:flat, :wait_interval => 2) do
330
+ puts 'This is run within a Bogo::Retry::Flat instance!'
331
+ end
332
+ ```
333
+
334
+ If the value of the action is required, disable auto run
335
+ and explicitly start the retry:
336
+
337
+ ```ruby
338
+ value = Bogo::Retry.build(:flat, :auto_run => false) do
339
+ puts 'This is run within a Bogo::Retry::Flat instance!'
340
+ 42
341
+ end.run!
342
+ ```
343
+
344
+ A block can also be provided to `run!` which will be called
345
+ when an exception is rescued to determine if the request should
346
+ be retried:
347
+
348
+ ```ruby
349
+ value = Bogo::Retry.build(:flat, :auto_run => false) do
350
+ puts 'This is run within a Bogo::Retry::Flat instance!'
351
+ 42
352
+ end.run! do |exception|
353
+ exception.is_a?(ErrorThatShouldBeRetried)
354
+ end
355
+ ```
356
+
357
+ #### `Bogo::Retry::Flat`
358
+
359
+ The flat retry implementation will always wait the `wait_interval`
360
+ value before retry.
361
+
362
+ * `:wait_interval` - Numeric (default: 5)
363
+
364
+ #### `Bogo::Retry::Linear`
365
+
366
+ The linear retry implementation will increase the wait time between
367
+ retries at a linear rate before retry:
368
+
369
+ * `:wait_interval` - Numeric (default: 5)
370
+
371
+ #### `Bogo::Retry::Exponential`
372
+
373
+ The exponential retry implementation will increase the wait time
374
+ between retries at an exponential rate before retry:
375
+
376
+ * `:wait_interval` - Numeric (default: 5)
377
+ * `:wait_exponent` - Numeric (default: 2)
378
+
313
379
  # Info
314
380
  * Repository: https://github.com/spox/bogo
@@ -67,7 +67,7 @@ module Bogo
67
67
  def valid_state
68
68
  data.merge!(dirty)
69
69
  dirty.clear
70
- @_checksum = Digest::SHA256.hexdigest(MultiJson.dump(data).to_s)
70
+ @_checksum = Digest::SHA256.hexdigest(MultiJson.dump(data.inspect).to_s)
71
71
  self
72
72
  end
73
73
 
@@ -81,7 +81,7 @@ module Bogo
81
81
  else
82
82
  if(@_checksum)
83
83
  !dirty.empty? ||
84
- @_checksum != Digest::SHA256.hexdigest(MultiJson.dump(data))
84
+ @_checksum != Digest::SHA256.hexdigest(MultiJson.dump(data.inspect).to_s)
85
85
  else
86
86
  true
87
87
  end
@@ -52,7 +52,10 @@ module Bogo
52
52
 
53
53
  # Run action until success
54
54
  #
55
- # return [Object] result of action
55
+ # @yield optional to allow custom exception check
56
+ # @yieldparam [Exception] exception caught
57
+ # @yieldreturn [TrueClass, FalseClass] if retry should be peformed
58
+ # @return [Object] result of action
56
59
  def run!
57
60
  if(dead)
58
61
  raise RuntimeError.new "Action has already reached maximum allowed attempts (#{max_attempts})!"
@@ -61,6 +64,9 @@ module Bogo
61
64
  log_attempt!
62
65
  action.call
63
66
  rescue => e
67
+ if(block_given?)
68
+ raise unless yield(e)
69
+ end
64
70
  if(max_attempts.nil? || attempts < max_attempts)
65
71
  interval = wait_on_failure(e)
66
72
  if(ui)
@@ -72,7 +78,7 @@ module Bogo
72
78
  sleep(interval)
73
79
  retry
74
80
  else
75
- if(ui)
81
+ if(ui && max_attempts.to_i > 0)
76
82
  ui.error "#{description} failed (#{e.class}: #{e}) - Maximum number of attempts reached!"
77
83
  end
78
84
  @dead = true
@@ -135,24 +141,17 @@ module Bogo
135
141
 
136
142
  # @return [Numeric]
137
143
  attr_reader :wait_interval
138
- # @return [Numeric]
139
- attr_reader :wait_multiplier
140
144
 
141
145
  # Create a new linear retry instance
142
146
  #
143
147
  # @param args [Hash]
144
148
  # @option args [Numeric] :wait_interval Defaults to 5 seconds
145
- # @option args [Numeric] :wait_multiplier Defaults to 2
146
149
  # @return [self]
147
150
  def initialize(args={}, &block)
148
151
  @wait_interval = args[:wait_interval].to_f
149
- @wait_multiplier = args[:wait_multiplier].to_f
150
152
  unless(@wait_interval > 0)
151
153
  @wait_interval = 5
152
154
  end
153
- unless(@wait_multiplier > 0)
154
- @wait_multiplier = 2
155
- end
156
155
  super
157
156
  end
158
157
 
@@ -1,4 +1,4 @@
1
1
  module Bogo
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.28')
3
+ VERSION = Gem::Version.new('0.1.30')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bogo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie