-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[v2] S3 progress indicator frequency #9545
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: cli-accessibility
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -315,7 +315,9 @@ class ResultPrinter(BaseResultHandler): | |
SRC_DEST_TRANSFER_LOCATION_FORMAT = '{src} to {dest}' | ||
SRC_TRANSFER_LOCATION_FORMAT = '{src}' | ||
|
||
def __init__(self, result_recorder, out_file=None, error_file=None): | ||
def __init__( | ||
self, result_recorder, out_file=None, error_file=None, frequency=0, oneline=True | ||
): | ||
"""Prints status of ongoing transfer | ||
|
||
:type result_recorder: ResultRecorder | ||
|
@@ -331,6 +333,8 @@ def __init__(self, result_recorder, out_file=None, error_file=None): | |
""" | ||
self._result_recorder = result_recorder | ||
self._out_file = out_file | ||
self._frequency = frequency | ||
self._first = True | ||
if self._out_file is None: | ||
self._out_file = sys.stdout | ||
self._error_file = error_file | ||
|
@@ -347,12 +351,31 @@ def __init__(self, result_recorder, out_file=None, error_file=None): | |
DryRunResult: self._print_dry_run, | ||
FinalTotalSubmissionsResult: self._clear_progress_if_no_more_expected_transfers, | ||
} | ||
self._now = time.time() | ||
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. non-blocking: seems this initial value is never used, consider initializing to |
||
self._oneline = oneline | ||
|
||
def __call__(self, result): | ||
"""Print the progress of the ongoing transfer based on a result""" | ||
self._result_handler_map.get(type(result), self._print_noop)( | ||
result=result | ||
) | ||
result_handler = self._result_handler_map.get(type(result), self._print_noop) | ||
if type(result) is ProgressResult: | ||
result_handler = self._override_progress_result_handler( | ||
result, result_handler | ||
) | ||
result_handler(result=result) | ||
|
||
def _override_progress_result_handler(self, result, result_handler): | ||
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. non-blocking question: have we considered modifying |
||
if ( | ||
type(result) in [ProgressResult] | ||
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. nit: could this be |
||
and ( | ||
self._first | ||
or (self._frequency == 0) | ||
or (time.time() - self._now >= self._frequency) | ||
) | ||
): | ||
self._now = time.time() | ||
self._first = False | ||
return result_handler | ||
return self._print_noop | ||
|
||
def _print_noop(self, **kwargs): | ||
# If the result does not have a handler, then do nothing with it. | ||
|
@@ -463,15 +486,19 @@ def _print_progress(self, **kwargs): | |
if not self._result_recorder.expected_totals_are_final(): | ||
progress_statement += self._STILL_CALCULATING_TOTALS | ||
|
||
# Make sure that it overrides any previous progress bar. | ||
progress_statement = self._adjust_statement_padding( | ||
progress_statement, ending_char='\r' | ||
) | ||
# We do not want to include the carriage return in this calculation | ||
# as progress length is used for determining whitespace padding. | ||
# So we subtract one off of the length. | ||
self._progress_length = len(progress_statement) - 1 | ||
|
||
if self._oneline: | ||
# Make sure that it overrides any previous progress bar. | ||
progress_statement = self._adjust_statement_padding( | ||
progress_statement, ending_char='\r' | ||
) | ||
# We do not want to include the carriage return in this calculation | ||
# as progress length is used for determining whitespace padding. | ||
# So we subtract one off of the length. | ||
self._progress_length = len(progress_statement) - 1 | ||
else: | ||
progress_statement = self._adjust_statement_padding( | ||
progress_statement, ending_char='\n' | ||
) | ||
# Print the progress out. | ||
self._print_to_out_file(progress_statement) | ||
|
||
|
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.
Can we add docs for
frequency
andoneline
?