Skip to content

added progress chunk to limit logging #2024

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

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions claims_hosp/delphi_claims_hosp/download_claims_ftp_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def missing_host_key(self, client, hostname, key):
return


def print_callback(filename, logger, bytes_so_far, bytes_total):
def print_callback(filename, logger, bytes_so_far, bytes_total, progress_chunks):
"""Print the callback information."""
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
if (rough_percent_transferred % 25) == 0:
if rough_percent_transferred in progress_chunks:
logger.info("Transfer in progress", filename=filename, percent=rough_percent_transferred)
progress_chunks.remove(rough_percent_transferred)

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

# download!
for infile, outfile in filepaths_to_download.items():
callback_for_filename = functools.partial(print_callback, infile, logger)
callback_for_filename = functools.partial(print_callback, infile, logger, progress_chunks=[0, 25, 50, 75])
sftp.get(infile, outfile, callback=callback_for_filename)
logger.info("Transfer in progress", filename=infile, percent=100)

client.close()
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def missing_host_key(self, client, hostname, key):
return


def print_callback(filename, logger, bytes_so_far, bytes_total):
def print_callback(filename, logger, bytes_so_far, bytes_total, progress_chunks):
"""Print the callback information."""
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
if (rough_percent_transferred % 25) == 0:
if rough_percent_transferred in progress_chunks:
logger.info("Transfer in progress", filename=filename, percent=rough_percent_transferred)

progress_chunks.remove(rough_percent_transferred)

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

# download!
for infile, outfile in filepaths_to_download.items():
callback_for_filename = functools.partial(print_callback, infile, logger)
callback_for_filename = functools.partial(print_callback, infile, logger, progress_chunks=[0, 25, 50, 75])
sftp.get(infile, outfile, callback=callback_for_filename)
logger.info("Transfer in progress", filename=infile, percent=100)

client.close()
Binary file not shown.
Loading