tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Improves wait_exponential_jitter

Open yxtay opened this issue 2 years ago • 3 comments

Summary

Improves wait_exponential_jitter to inherit wait_exponential - Reuses wait_exponential.__call__ method instead of of duplicating code - Follows argument names of wait_exponential - Adds min argument - Supports supplying max, jitter, min arguments as timedelta

Tests

pytest tests/test_tenacity.py::TestWaitConditions::test_wait_exponential_jitter

yxtay avatar Dec 18 '23 03:12 yxtay

Is there anything blocking this from being merged? Deprecation concerns? It's been almost 1 year.

yxtay avatar Nov 14 '24 02:11 yxtay

Hi @yxtay , in the case min > initial * exp , the result will be wrong (not equivalent to the original formula). example : min == 100; max == 10^9; initial * exp == 8; jitter == 10

  • Original formula (+adding the min value)

max(max(0, min), min(result, self.max)) == max(max(0, min), min(initial * exp + jitter, max)) == max(max(0, 100), min(18, 10^9)) == max(100, 18) == 100

  • Formula in this PR
 max(max(0, 100), min(max(max(0, min), min(initial * exp, self.max)) + jitter, max) == 
 max(max(0, 100), min(max(max(0, 100), min(8, 10^9)) + 10, 10^9) == 
 max(100, min(100 + 10, 10^9) == max(100, 110) == 110

The correct thing to do is to leave the implementation of wait_exponential_jitter separate from the wait_exponential (because its adding jitter before comparing with max, min values..).

LotfiRafik avatar Feb 20 '25 07:02 LotfiRafik

:wave: I was just looking at implementing the min and the typing improvements that you added here @yxtay, I feel like they'd still be nice api improvements.

Would it make sense to split those commits off to be merged while @LotfiRafik 's comments are addressed?

krispenney avatar Oct 23 '25 02:10 krispenney