Skip to content

feat: add wait_fibonacci strategy#623

Open
samuelefiorini wants to merge 5 commits intojd:mainfrom
samuelefiorini:devs/samu/feat/fibonacci-wait
Open

feat: add wait_fibonacci strategy#623
samuelefiorini wants to merge 5 commits intojd:mainfrom
samuelefiorini:devs/samu/feat/fibonacci-wait

Conversation

@samuelefiorini
Copy link

Summary

Adds a new wait_fibonacci wait strategy that increases retry delays following the Fibonacci sequence (1s, 2s, 3s, 5s, 8s, 13s, …), capped by an optional max parameter.

Fibonacci backoff is a compromise between linear and exponential backoff — it ramps up more gently than exponential, making it a good fit for scenarios where a resource might be temporarily unavailable and you want to reduce latency without overwhelming the server.

Example

@retry(wait=wait_fibonacci(max=60))
def call_flaky_service():
    ...

Design notes

  • Stateful: unlike most wait strategies that compute from retry_state.attempt_number, wait_fibonacci maintains an internal sequence. This is called out in the docstring with a .. note:: directive.
  • max parameter supports both int/float and timedelta, consistent with other wait strategies.
  • OverflowError handling: for extremely long retry sequences, an OverflowError is caught and the max value is returned.

Checklist

  • Implementation in tenacity/wait.py
  • Exported in __init__.py and __all__
  • Tests in tests/test_tenacity.py (4 test methods following existing patterns)
  • Documentation in doc/source/index.rst
  • Release note
  • All checks pass (poe all — linting, formatting, mypy, pytest, doctests, docs build)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant