Declutter __init__ by using strategy selection#55
Declutter __init__ by using strategy selection#55harlowja wants to merge 1 commit intorholder:masterfrom
Conversation
Instead of having there be a complicated __init__ function that has to make a bunch of complicated decisions this change moves the logic for making those decisions into a set of helper functions that now select the various wait/stop/reject strategies to use when retrying. This will hopefully make it easier to add new strategies as well as move forward to a path where users can provide there own strategies (if they so want to).
|
My initial $0.01: In particular, I'm not a huge fan of the current init scheme lumping all args together as I find it confusing on the behavior if you specify values for different wait schemes (for example). I'd prefer a more modular interface where retrying provides (pluggable/composable) building blocks for retry behavior. For example basic "abstract interfaces" for the major pluggable behavior (sleep time, stop, etc.), chaining, etc. I was imagining something like this usage for example: # simple fixed waited and stop after attempts
@retry(wait=retrying.FixedWait(1000), stop=retrying.StopOnMaxAttempt(7))
def basic_retry():
useful_stuff()
# chained behavior
wait_chain = retrying.CallChain(retrying.FixedWait(1000),
my_custom_fn)
stop_chain = retrying.CallChain(retrying.StopOnMaxDelay(11.21),
my_custom_stop_fn)
@retry(wait=wait_chain, stop=stop_chain)
def chained_retry():
more_useful_stuff()
# custom plugins
class MyWait(retrying.WaitBase):
def sleep(self, attempts, prev):
return prev * attempts
@retry(wait=MyWait(), stop=retrying.StopOnMaxAttempt(7))
def custom_retry():
useful_things()Are you guys open to a major change (major revision), or should we just continue to enhance the existing interface? |
|
Yes, I'd like the building blocks u state; which I think this strategy 'refactor' can help us get to. Should it just be a major revision, probably. Should we go farther and expose those strategies for public use/changing/chaining... in that revision, maybe? |
|
Fair enough. Let me find some time tomorrow (hopefully) to review your PR. |
|
@harlowja I'd be happy to take a 1st shot at approximating a new revision if you guys are willing to consider it as a starting/talking point? If you guys all think the refactor in this PR should move forward; I'm certainly on-board and willing to review, but again I'd rather see us focus on a major revision with interface changes. Just my $0.01 |
|
@bodenr I don't disagree. I'd just rather have the owner/creator of retrying chime-in before we do such a retrying 2.0 (or whatever u want to call it). |
|
@rholder what are your thought in regards to the discussion above (e.g. updated/new interface for a "major revision" of retrying)? |
|
Hi @rholder Any chance you can try to weigh-in on this thread? Based on discussions we've had (see comments herein as well as in [1][2]), enhancing retrying's modularity/pluggability is paramount to supporting new functionality in a clean manner. I'm more than happy to drive this work; just looking for your blessing :) Thanks |
Instead of having there be a complicated
__init__function that has to make a bunch of complicated
decisions this change moves the logic for making
those decisions into a set of helper functions that
now select the various wait/stop/reject strategies
to use when retrying.
This will hopefully make it easier to add new
strategies as well as move forward to a path where
users can provide there own strategies (if they
so want to).