Open zhaohanyan opened 2 days ago
In our custom function use case, we would like to check if the Retry-After
header specifies a wait time that exceeds max_time
. If it does, we prefer to skip waiting and immediately return, saving time by not waiting longer than necessary.
Issue: Access to Decorator Parameters in
on_backoff
HandlersDescription
Currently, when using
backoff
decorators like@backoff.on_predicate
or@backoff.on_exception
, theon_backoff
handlers only receive adetails
dictionary with limited information. However, important decorator parameters, such asmax_time
andmax_tries
, are not accessible in thedetails
, which can limit flexibility in implementing complex backoff handling logic. Additionally, there is no direct way to pass additional parameters toon_backoff
handlers.Problem
For use cases where
on_backoff
handling may need to consider or log values likemax_time
andmax_tries
(especially if they are dynamic), users currently need to implement workarounds such as using global variables, environment variables, orfunctools.partial
. These methods, while functional, can make the code less readable and maintainable.Allowing direct access to decorator parameters like
max_time
andmax_tries
withinon_backoff
handlers would simplify configuration and enhance functionality. Additionally, supporting the option to pass custom parameters into theon_backoff
handler would add flexibility for more complex backoff strategies.Proposed Solution
details
: Addmax_time
,max_tries
, and other relevant parameters from the decorator into thedetails
dictionary.on_backoff
Handlers: Permiton_backoff
handlers to accept additional arguments beyonddetails
, enabling more flexible configuration.Example Usage
Benefit
This enhancement would improve flexibility and code readability when working with backoff configurations and would allow more sophisticated use cases to be handled more naturally.