Skip to content

Commit 2184da7

Browse files
authored
added progress chunk to limit logging (#2024)
* added progress chunk to limit logging * lint * comment based on suggestion
1 parent c7bf03e commit 2184da7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

claims_hosp/delphi_claims_hosp/download_claims_ftp_files.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ def missing_host_key(self, client, hostname, key):
1919
return
2020

2121

22-
def print_callback(filename, logger, bytes_so_far, bytes_total):
22+
def print_callback(filename, logger, bytes_so_far, bytes_total, progress_chunks):
2323
"""Print the callback information."""
2424
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
25-
if (rough_percent_transferred % 25) == 0:
25+
if rough_percent_transferred in progress_chunks:
2626
logger.info("Transfer in progress", filename=filename, percent=rough_percent_transferred)
27+
# Remove progress chunk, so it is not logged again
28+
progress_chunks.remove(rough_percent_transferred)
2729

2830
OLD_FILENAME_TIMESTAMP = re.compile(
2931
r".*EDI_AGG_INPATIENT_[0-9]_(?P<ymd>[0-9]*)_(?P<hm>[0-9]*)[^0-9]*")
@@ -95,7 +97,8 @@ def download(ftp_credentials, out_path, logger):
9597

9698
# download!
9799
for infile, outfile in filepaths_to_download.items():
98-
callback_for_filename = functools.partial(print_callback, infile, logger)
100+
callback_for_filename = functools.partial(print_callback, infile, logger, progress_chunks=[0, 25, 50, 75])
99101
sftp.get(infile, outfile, callback=callback_for_filename)
102+
logger.info("Transfer finished", filename=infile, percent=100)
100103

101104
client.close()

doctor_visits/delphi_doctor_visits/download_claims_ftp_files.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ def missing_host_key(self, client, hostname, key):
1919
return
2020

2121

22-
def print_callback(filename, logger, bytes_so_far, bytes_total):
22+
def print_callback(filename, logger, bytes_so_far, bytes_total, progress_chunks):
2323
"""Print the callback information."""
2424
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
25-
if (rough_percent_transferred % 25) == 0:
25+
if rough_percent_transferred in progress_chunks:
2626
logger.info("Transfer in progress", filename=filename, percent=rough_percent_transferred)
27-
27+
# Remove progress chunk, so it is not logged again
28+
progress_chunks.remove(rough_percent_transferred)
2829

2930
OLD_FILENAME_TIMESTAMP = re.compile(
3031
r".*EDI_AGG_OUTPATIENT_[0-9]_(?P<ymd>[0-9]*)_(?P<hm>[0-9]*)[^0-9]*")
@@ -100,7 +101,8 @@ def download(ftp_credentials, out_path, logger, issue_date=None):
100101

101102
# download!
102103
for infile, outfile in filepaths_to_download.items():
103-
callback_for_filename = functools.partial(print_callback, infile, logger)
104+
callback_for_filename = functools.partial(print_callback, infile, logger, progress_chunks=[0, 25, 50, 75])
104105
sftp.get(infile, outfile, callback=callback_for_filename)
106+
logger.info("Transfer finished", filename=infile, percent=100)
105107

106108
client.close()

0 commit comments

Comments
 (0)