-
Notifications
You must be signed in to change notification settings - Fork 16
Added minimal logging #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
import random | ||
import six | ||
import sys | ||
|
@@ -83,6 +83,7 @@ def __init__( | |
wait_jitter_max=None, | ||
before_attempts=None, | ||
after_attempts=None, | ||
logger=None, | ||
): | ||
|
||
self._stop_max_attempt_number = ( | ||
|
@@ -110,6 +111,7 @@ def __init__( | |
self._wait_jitter_max = 0 if wait_jitter_max is None else wait_jitter_max | ||
self._before_attempts = before_attempts | ||
self._after_attempts = after_attempts | ||
self._logger = logging.getLogger(__name__) if logger is None else logger | ||
|
||
# TODO add chaining of stop behaviors | ||
# stop behavior | ||
|
@@ -256,6 +258,7 @@ def call(self, fn, *args, **kwargs): | |
if not self.should_reject(attempt): | ||
return attempt.get(self._wrap_exception) | ||
|
||
self._logger.warn(attempt) | ||
if self._after_attempts: | ||
self._after_attempts(attempt_number) | ||
|
||
|
@@ -268,6 +271,7 @@ def call(self, fn, *args, **kwargs): | |
raise RetryError(attempt) | ||
else: | ||
sleep = self.wait(attempt_number, delay_since_first_attempt_ms) | ||
self._logger.info(f"Retrying in {sleep / 1000.0:.2f} seconds.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [blocking] This line should be below the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: NM, I read it to quickly 😁. Moving below 👍 |
||
if self._wait_jitter_max: | ||
jitter = random.random() * self._wait_jitter_max | ||
sleep = sleep + max(0, jitter) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[blocking] This is okay, but I hate having a library change behavior wrt logging.
Maybe something like: