Skip to content

Commit

Permalink
[PRMP-1063] moved CSV creation and upload logic into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyFlintNHS committed Oct 29, 2024
1 parent aff278e commit 62866aa
Showing 1 changed file with 16 additions and 45 deletions.
61 changes: 16 additions & 45 deletions lambdas/services/bulk_upload_report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,8 @@ def generate_success_report(self, ods_reports: list[OdsReport]):
)

if data_rows:
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

logger.info("Uploading daily success report file to S3")
self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)
self.write_and_upload_additional_reports(file_name, headers, data_rows)
else:
logger.info("No data to report for daily success report file")

Expand All @@ -190,16 +182,8 @@ def generate_suspended_report(self, ods_reports: list[OdsReport]):
)

if data_rows:
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

logger.info("Uploading daily suspended report file to S3")
self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)
self.write_and_upload_additional_reports(file_name, headers, data_rows)
else:
logger.info("No data to report for daily suspended report file")

Expand Down Expand Up @@ -227,16 +211,8 @@ def generate_deceased_report(self, ods_reports: list[OdsReport]):
)

if data_rows:
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

logger.info("Uploading daily deceased report file to S3")
self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)
self.write_and_upload_additional_reports(file_name, headers, data_rows)
else:
logger.info("No data to report for daily deceased report file")

Expand All @@ -258,16 +234,8 @@ def generate_restricted_report(self, ods_reports: list[OdsReport]):
)

if data_rows:
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

logger.info("Uploading daily restricted report file to S3")
self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)
self.write_and_upload_additional_reports(file_name, headers, data_rows)
else:
logger.info("No data to report for daily deceased report file")

Expand Down Expand Up @@ -296,16 +264,8 @@ def generate_rejected_report(self, ods_reports: list[OdsReport]):
)

if data_rows:
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

logger.info("Uploading daily rejected report file to S3")
self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)
self.write_and_upload_additional_reports(file_name, headers, data_rows)
else:
logger.info("No data to report for daily rejected report file")

Expand Down Expand Up @@ -415,3 +375,14 @@ def get_times_for_scan(self) -> tuple[datetime, datetime]:
self.s3_key_prefix = f"bulk-upload-reports/{date_folder_name}"

return start_timestamp, end_timestamp

def write_and_upload_additional_reports(self, file_name, headers, data_rows):
self.write_additional_report_items_to_csv(
file_name=file_name, headers=headers, rows_to_write=data_rows
)

self.s3_service.upload_file(
s3_bucket_name=self.reports_bucket,
file_key=f"{self.s3_key_prefix}/{file_name}",
file_name=f"/tmp/{file_name}",
)

0 comments on commit 62866aa

Please sign in to comment.