python-circuit
python-circuit copied to clipboard
Not sure of how backoff_cap works
In the code:
delay_time = self.backoff_cap and min(self.reset_timeout * (2 ** self.test_fail_count), self.backoff_cap) or self.reset_timeout
I am not sure about self.backoff_cap and ...
It look to me that no matter what value you pass for backoff_cap, as long as it's not 0, the value itself is ignored and the expression after "and" determines the actually delay time.
Am I missing something ? Should backoff_cap be the maximum backoff time ? (in which case you probably need to use something like max(backoff_cap, calculated_delay_time)
Thanks!
It look to me that no matter what value you pass for backoff_cap, as long as it's not 0, the value itself is ignored and the expression after "and" determines the actually delay time.
It's the other way around, as long as backoff_cap is non-zero, we will end up in the min(self.reset_timeout * (2 ** self.test_fail_count), self.backoff_cap) expression to determine the value of delay_time.
It could be written like this as well, if that helps:
if self.backoff_cap == 0:
delay_time = self.reset_timeout
else:
delay_time = min(self.reset_timeout * (2 ** self.test_fail_count), self.backoff_cap)
Or did I misunderstand you? :)