retriable 4.0.0 → 4.1.0

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
  SHA256:
3
- metadata.gz: 392e6bc1b69a4c85c286f5df1b90c5991243cd7290cd3b41c028f253ad16dae4
4
- data.tar.gz: f078e585b65160045cc71e4a9f8746b7b480645cf841ff13a7bbbec78fc9ffeb
3
+ metadata.gz: 13cb5eedc133750c87f4678e0e94d1500e1d2c81ef474d0f38fd5ebff14b04a0
4
+ data.tar.gz: 773776c2ff6ae25aa3cc4202eb851086274204955df5c602dd6b147a17015103
5
5
  SHA512:
6
- metadata.gz: 01dc250d04fbc71c89d6af526ab061ec4439d382ec50872776859415df9bad2d1d4c8f2e0cfb53fc263343d72871ce691df5840721d33caf0ccaacee03bf9f6e
7
- data.tar.gz: f1ae42a3015541313322371fd297f5f677d1a974747b48a524c25e1f676fc7adeb8d309975851198c69632fc124a34e4db5488486783a40beb8758ef12cf6c01
6
+ metadata.gz: 94477379cf7000dd9f81d0926ab02bfeffe31ebdec477ff930281cf8ba67f72c6fe78a116bb7e777f532bf0a58ae91da0a9b87c0dc927d51a754aaac36cef793
7
+ data.tar.gz: 63f3d0141d5efa4bf789455c10607e85ba2a1fde60cf834ba500b48cfe1bd0f9993e7cefb8ee77beb87e5c0e75034d24860a826330ee920e51a9313353bcd472
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # HEAD
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Bug fixes
6
+
7
+ - A per-call or `with_context` `tries:` now clears an inherited `intervals:` from
8
+ global config or a context, matching the documented precedence. Previously
9
+ `Retriable.retriable(tries: 1)` was silently ignored when `intervals` was
10
+ configured, running `intervals.size + 1` times. Passing both `intervals:` and
11
+ `tries:` in the same call still lets `intervals:` win.
12
+
3
13
  ## 4.0.0
4
14
 
5
15
  **This is a major release with breaking changes. Please read carefully before upgrading.**
data/README.md CHANGED
@@ -206,6 +206,11 @@ end
206
206
  `#configure` sets defaults only. Per-call options passed to `Retriable.retriable` and
207
207
  `Retriable.with_context` still take precedence.
208
208
 
209
+ When a higher-precedence layer sets `tries:` without `intervals:`, it clears any
210
+ `intervals:` inherited from a lower layer (so `retriable(tries: 1)` runs once even
211
+ if `intervals` was configured). Within a single call, passing `intervals:` still
212
+ overrides `tries:`.
213
+
209
214
  ### Override
210
215
 
211
216
  `#with_override` is a block-scoped API for forcing retry options that should
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Retriable
4
- VERSION = "4.0.0"
4
+ VERSION = "4.1.0"
5
5
  end
data/lib/retriable.rb CHANGED
@@ -58,7 +58,7 @@ module Retriable
58
58
  local_config = if opts.empty? && !override_config
59
59
  config
60
60
  else
61
- Config.new(apply_override_options(config.to_h.merge(opts), override_config))
61
+ Config.new(apply_override_options(merge_layer(config.to_h, opts), override_config))
62
62
  end
63
63
 
64
64
  # Config is mutable through `configure`, so validate again immediately before use.
@@ -216,9 +216,17 @@ module Retriable
216
216
  def apply_override_options(options, overrides)
217
217
  return options unless overrides
218
218
 
219
- options = options.merge(overrides)
220
- options[:intervals] = nil if overrides.key?(:tries) && !overrides.key?(:intervals)
221
- options
219
+ merge_layer(options, overrides)
220
+ end
221
+
222
+ # Merge a higher-precedence option layer onto a base layer. A higher layer
223
+ # that sets `tries` without `intervals` clears the base layer's inherited
224
+ # `intervals`, so a caller's `tries:` is never silently ignored. When the
225
+ # higher layer supplies its own `intervals`, those win (same-call override).
226
+ def merge_layer(base, higher)
227
+ merged = base.merge(higher)
228
+ merged[:intervals] = nil if higher.key?(:tries) && !higher.key?(:intervals)
229
+ merged
222
230
  end
223
231
 
224
232
  def available_contexts
@@ -228,7 +236,7 @@ module Retriable
228
236
  def context_options_for(context_key, options)
229
237
  context_options = config_contexts.fetch(context_key, {})
230
238
  context_options = {} unless context_options.is_a?(Hash)
231
- context_options = context_options.merge(options)
239
+ context_options = merge_layer(context_options, options)
232
240
 
233
241
  override_context_options = override_contexts[context_key]
234
242
  return context_options unless override_context_options.is_a?(Hash)
@@ -262,6 +270,7 @@ module Retriable
262
270
  :retriable_exception?,
263
271
  :hash_exception_match?,
264
272
  :apply_override_options,
273
+ :merge_layer,
265
274
  :available_contexts,
266
275
  :context_options_for,
267
276
  :config_contexts,
@@ -760,6 +760,38 @@ describe Retriable do
760
760
  end
761
761
  end
762
762
 
763
+ context "#retriable tries/intervals precedence" do
764
+ it "lets a per-call tries clear globally configured intervals" do
765
+ described_class.configure { |c| c.intervals = [0.5, 1.0] }
766
+
767
+ expect do
768
+ described_class.retriable(tries: 1) { increment_tries_with_exception }
769
+ end.to raise_error(StandardError)
770
+
771
+ expect(@tries).to eq(1)
772
+ end
773
+
774
+ it "still lets per-call intervals win when both intervals and tries are given" do
775
+ expect do
776
+ described_class.retriable(intervals: [0.5, 1.0], tries: 1) { increment_tries_with_exception }
777
+ end.to raise_error(StandardError)
778
+
779
+ expect(@tries).to eq(3) # intervals.size + 1
780
+ end
781
+
782
+ it "lets a with_context tries clear context intervals" do
783
+ described_class.configure do |c|
784
+ c.contexts[:api] = { intervals: [0.5, 1.0] }
785
+ end
786
+
787
+ expect do
788
+ described_class.with_context(:api, tries: 1) { increment_tries_with_exception }
789
+ end.to raise_error(StandardError)
790
+
791
+ expect(@tries).to eq(1)
792
+ end
793
+ end
794
+
763
795
  context "#with_override" do
764
796
  it "takes precedence over both global config and local options" do
765
797
  described_class.configure { |c| c.tries = 2 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chu