Add opt-in infinite retries with elapsed-time guard#120
Conversation
e758f8e to
73cb938
Compare
Support infinite retry loops bounded by max_elapsed_time, useful for long-running worker processes. Raises ArgumentError if max_elapsed_time is not finite or if custom intervals are empty. Extracts interval_for on ExponentialBackoff for lazy per-attempt interval computation without pre-allocating an array.
591a500 to
e121ead
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if local_config.intervals | ||
| raise ArgumentError, "intervals must not be empty for infinite retries" if local_config.intervals.empty? | ||
|
|
||
| custom = local_config.intervals | ||
| interval_for = ->(i) { custom[[i, custom.size - 1].min] } | ||
| else |
There was a problem hiding this comment.
In tries: :infinite mode with custom intervals, only the empty-array case is validated. If intervals contains nil or non-numeric values, interval_for can return a non-numeric interval and can_retry? will raise a TypeError when evaluating elapsed_time + interval. Consider validating that all interval values (and especially the last value, since it is reused) are Numeric, and raising a clear ArgumentError if not (and adding a spec for this behavior).
| else | ||
| backoff = ExponentialBackoff.new( | ||
| base_interval: local_config.base_interval, multiplier: local_config.multiplier, | ||
| max_interval: local_config.max_interval, rand_factor: local_config.rand_factor |
There was a problem hiding this comment.
This multiline ExponentialBackoff.new(...) call is missing a trailing comma after the last argument. The repo’s RuboCop config enforces trailing commas for multiline argument lists (Style/TrailingCommaInArguments), so this will fail linting.
| max_interval: local_config.max_interval, rand_factor: local_config.rand_factor | |
| max_interval: local_config.max_interval, rand_factor: local_config.rand_factor, |
Summary
tries: :infinitewithout changing existing finite retry defaultsmax_elapsed_timeto be finite when infinite retries are enabledTesting