chrono_machines 0.11.0-aarch64-linux → 0.12.0-aarch64-linux

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: fc22547860d54b36a7bc9c5c2afabc18840c94869a924a8318ea50036924f374
4
- data.tar.gz: ab5a3d65ec8e91f04dfdb8eb0b6327bd5cbf5aba9be015f800be78a6c7d7e037
3
+ metadata.gz: f9cbe0bcc4e1a9a8b286eabcab9b3f15bc74d28a91ce04b0aecda3d4e781670b
4
+ data.tar.gz: 066e08f1c403bdd2c3774007a9b115e5b89377eb43c0d81a24e7f181d4f27a3c
5
5
  SHA512:
6
- metadata.gz: 0aa6eeb316ac2a1a415bc5e92682554bef7cedbcd52bca87b597ff8e32b1f1a7696954e0247c994e7dd3ab06435a1cb42c1fe0176641dc06e3146bc62027c27b
7
- data.tar.gz: 26a71d24a664a8b19ece84ca8199c8200b4b5fa133820ae36fde090c05813eaaf5e9a7bf595aee17781c36546cdf556bccd669a84c30e16b3e4a5f2cac5fed23
6
+ metadata.gz: b933ad2cd45d43512e5bc5b3eedb5b574736d490773649e3c30b40a8363c4885a04c278a0eecddccea3efb53eb7e262e37f13e9f6477992bbb495d99c57538ed
7
+ data.tar.gz: eca8035836bd8e81b7b04129a195302d2ec5055702cf2ed8557daf0a6fb823b60fb08c93e67dbba49e7c0eaf0efd2f84820571c28df53aa160592309e1e96795
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.12.0](https://github.com/seuros/chrono_machines/compare/chrono_machines/v0.11.0...chrono_machines/v0.12.0) (2026-11-01)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * `chrono_machines::fibonacci` returns f64, and `max_attempts` outside 1..255 is rejected instead of silently computed on one backend only.
9
+
10
+ ### Features
11
+
12
+ * expose full jitter as a one-shot ([ff78a9c](https://github.com/seuros/chrono_machines/commit/ff78a9ca3a9e3a3b3a64a5427290e9f72e55305a))
13
+ * honour an ambient deadline during retries ([97b24d0](https://github.com/seuros/chrono_machines/commit/97b24d0b73751a6a25f1ee703cb251ff43ed167a))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * a failing success callback no longer re-runs the operation ([920ecc9](https://github.com/seuros/chrono_machines/commit/920ecc9002b66a7617ed99537c63ab6b2238c1ba))
19
+ * a lone checkout can bundle ([19276ef](https://github.com/seuros/chrono_machines/commit/19276ef6b78f0a13c18c7d23e91e2830d9cf0b1c))
20
+ * a source install can build, and a failed gem push fails the release ([cd85f2c](https://github.com/seuros/chrono_machines/commit/cd85f2cc5270830a89b35e7217a10e2454813ab3))
21
+ * build the native speedup on CRuby only ([0b30fc6](https://github.com/seuros/chrono_machines/commit/0b30fc61b753908a9bff39e77b8854ab74ef603f))
22
+ * Fibonacci backoff no longer saturates on the native backend ([213413c](https://github.com/seuros/chrono_machines/commit/213413ce86af8107396d8462449e7cebd2430e17))
23
+ * load the native build tasks on CRuby only ([f0826ca](https://github.com/seuros/chrono_machines/commit/f0826ca5e9636facde86fb02fd30d5be28b683e0))
24
+ * ship the core's test files so the packaged crate builds ([89b1de5](https://github.com/seuros/chrono_machines/commit/89b1de5067b222de580d761ce17b439e8b689533))
25
+
3
26
  ## [0.11.0](https://github.com/seuros/chrono_machines/compare/chrono_machines/v0.10.0...chrono_machines/v0.11.0) (2026-10-14)
4
27
 
5
28
 
data/README.md CHANGED
@@ -39,7 +39,7 @@ Still here? Excellent. Because in the fabric of spacetime, nobody can hear your
39
39
 
40
40
  ### The Pattern Time Forgot
41
41
 
42
- Built for Ruby 3.2+ with fiber-aware sleep and full jitter implementation, because when you're manipulating time itself, precision matters.
42
+ Built for Ruby 4.0+ with fiber-aware sleep and full jitter implementation, because when you're manipulating time itself, precision matters.
43
43
 
44
44
  ## Features
45
45
 
@@ -282,7 +282,7 @@ Jitter is drawn from the `random:` option (Ruby's `Random` by default) on both b
282
282
 
283
283
  | Option | Default | Description |
284
284
  |--------|---------|-------------|
285
- | `max_attempts` | `3` | Maximum number of attempts, including the initial call |
285
+ | `max_attempts` | `3` | Maximum number of attempts, including the initial call; `1..255` |
286
286
  | `base_delay` | `0.1` | Initial delay in seconds |
287
287
  | `multiplier` | `2` | Exponential backoff multiplier |
288
288
  | `max_delay` | `10` | Maximum delay cap in seconds |
@@ -627,7 +627,7 @@ end
627
627
  ## Why ChronoMachines?
628
628
 
629
629
  ### Built for Modern Ruby
630
- - **Ruby 3.2+ Support**: Fiber-aware sleep handling
630
+ - **Ruby 4.0+ Support**: Fiber-aware sleep handling
631
631
  - **Clean Architecture**: Separation of concerns with configurable policies
632
632
  - **Rich Instrumentation**: Comprehensive callback system for monitoring
633
633
  - **Battle-Tested**: Full jitter implementation prevents thundering herds
@@ -2,6 +2,8 @@
2
2
 
3
3
  module ChronoMachines
4
4
  class Executor
5
+ ATTEMPT_LIMIT = 255
6
+
5
7
  def initialize(policy_or_options = {})
6
8
  policy_options = if policy_or_options.is_a?(Symbol)
7
9
  ChronoMachines.config.get_policy(policy_or_options)
@@ -11,6 +13,11 @@ module ChronoMachines
11
13
 
12
14
  @backoff_strategy = policy_options[:backoff_strategy] || :exponential
13
15
  @max_attempts = policy_options[:max_attempts]
16
+ unless @max_attempts.is_a?(Integer) && @max_attempts.between?(1, ATTEMPT_LIMIT)
17
+ raise ArgumentError, "max_attempts must be an Integer in 1..#{ATTEMPT_LIMIT} " \
18
+ "(the native backend counts attempts in a u8); got #{@max_attempts.inspect}"
19
+ end
20
+
14
21
  @base_delay = policy_options[:base_delay]
15
22
  @multiplier = policy_options[:multiplier] || 2
16
23
  @max_delay = policy_options[:max_delay]
@@ -34,16 +41,14 @@ module ChronoMachines
34
41
 
35
42
  def call
36
43
  attempts = 0
44
+ DeadlineMachines.check!
37
45
 
38
- begin
46
+ result = begin
39
47
  attempts += 1
40
- result = yield
41
-
42
- # Call success callback if defined
43
- @on_success&.call(result: result, attempts: attempts)
44
-
45
- result
48
+ yield
46
49
  rescue StandardError => e
50
+ raise if caller_gave_up?(e)
51
+
47
52
  delay = next_delay(attempt: attempts, exception: e)
48
53
  unless delay
49
54
  handle_final_failure(e, attempts)
@@ -52,17 +57,33 @@ module ChronoMachines
52
57
  raise e
53
58
  end
54
59
 
55
- # Call retry callback if defined
56
- @on_retry&.call(exception: e, attempt: attempts, next_delay: delay)
57
-
58
- # Execute delay with robust sleep
59
- robust_sleep(delay)
60
+ stop_on_spent_budget(e, attempts)
61
+ budget = DeadlineMachines.clamp_sleep(delay)
62
+ @on_retry&.call(exception: e, attempt: attempts, next_delay: budget)
63
+ robust_sleep(DeadlineMachines.clamp_sleep(budget))
64
+ stop_on_spent_budget(e, attempts)
60
65
  retry
61
66
  end
67
+
68
+ @on_success&.call(result: result, attempts: attempts)
69
+ result
62
70
  end
63
71
 
64
72
  private
65
73
 
74
+ # A deadline error from a narrower inner scope is a timeout worth retrying.
75
+ # One raised because this caller's own budget is gone is not.
76
+ def caller_gave_up?(error)
77
+ error.is_a?(DeadlineMachines::Error) && DeadlineMachines.current&.done?
78
+ end
79
+
80
+ def stop_on_spent_budget(exception, attempts)
81
+ return unless DeadlineMachines.current&.done?
82
+
83
+ handle_final_failure(exception, attempts)
84
+ DeadlineMachines.check!
85
+ end
86
+
66
87
  def retryable_exception?(exception)
67
88
  @retryable_exceptions.any? { |type| exception.is_a?(type) }
68
89
  end
@@ -105,16 +126,14 @@ module ChronoMachines
105
126
  apply_jitter(base_delay)
106
127
  end
107
128
 
108
- # Calculate Fibonacci number (1-indexed)
129
+ # The nth Fibonacci number (1-indexed), as a delay factor, accumulated step
130
+ # for step with `fibonacci` in ext/chrono_machines_native/core/src/backoff.rs,
131
+ # whose documentation covers why neither side counts in integers.
109
132
  def fibonacci(n)
110
- return 0 if n.zero?
111
- return 1 if n <= 2
112
-
113
- a, b = 1, 1
114
- (2...n).each do
115
- a, b = b, a + b
116
- end
117
- b
133
+ previous = 0.0
134
+ current = 1.0
135
+ n.times { previous, current = current, previous + current }
136
+ previous
118
137
  end
119
138
 
120
139
  # Main calculate_delay dispatches to the appropriate strategy
@@ -5,14 +5,9 @@
5
5
  # to use the native Rust implementation for delay calculations.
6
6
 
7
7
  begin
8
- # Try to load the native extension
9
- # Prefer local development version if it exists
10
- local_ext_path = File.expand_path('../../ext/chrono_machines_native/chrono_machines_native', __dir__)
11
- if File.exist?("#{local_ext_path}.bundle") || File.exist?("#{local_ext_path}.so")
12
- require local_ext_path
13
- else
14
- require 'chrono_machines_native/chrono_machines_native'
15
- end
8
+ # `rake compile` installs the extension here. A leftover build under ext/
9
+ # must not shadow it: that is how a stale native backend gets tested.
10
+ require 'chrono_machines_native/chrono_machines_native'
16
11
 
17
12
  module ChronoMachines
18
13
  # Native speedup module that overrides backoff calculations
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChronoMachines
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'deadline_machines'
3
4
  require 'zeitwerk'
4
5
 
5
6
  loader = Zeitwerk::Loader.for_gem
@@ -27,6 +28,17 @@ module ChronoMachines
27
28
  def self.retry(policy_name_or_options = {}, &)
28
29
  Executor.new(policy_name_or_options).call(&)
29
30
  end
31
+
32
+ # Full jitter over a single duration: the result lands in
33
+ # `seconds * (1 - factor)` to `seconds`, so a fleet of callers waiting the
34
+ # same nominal time does not wake up together.
35
+ def self.jitter(seconds, factor:, random: Random)
36
+ factor = Float(factor)
37
+ raise ArgumentError, 'factor cannot be NaN' if factor.nan?
38
+
39
+ factor = factor.clamp(0.0, 1.0)
40
+ seconds * (1 - factor + (random.rand * factor))
41
+ end
30
42
  end
31
43
 
32
44
  # Load optional async support after core is loaded
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrono_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-14 00:00:00.000000000 Z
11
+ date: 2026-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deadline_machines
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: zeitwerk
15
29
  requirement: !ruby/object:Gem::Requirement