Skip to content

Commit de259bd

Browse files
author
Scott Collins
committed
wip report table updates
1 parent 2ec6142 commit de259bd

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/pds/ingress/client/pds_ingress_client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ def _process_batch(batch_index, request_batch, node_id, force_overwrite, api_gat
164164
fully processed.
165165
166166
"""
167+
global SUMMARY_TABLE
168+
167169
logger = get_logger("_process_batch", console=False)
168170

169171
# Get an avaialble Batch progress bar to update while iterating through this
@@ -451,6 +453,8 @@ def ingress_file_to_s3(ingress_response, batch_index, batch_pbar):
451453
If an unexpected response is received from the Ingress Lambda app.
452454
453455
"""
456+
global SUMMARY_TABLE
457+
454458
logger = get_logger("ingress_file_to_s3", console=False)
455459

456460
response_result = int(ingress_response.get("result", -1))
@@ -477,12 +481,14 @@ def ingress_file_to_s3(ingress_response, batch_index, batch_pbar):
477481
with open(ingress_path, "rb") as infile:
478482
# Wrap file I/O with our upload bar to automatically track file upload progress
479483
wrapped_file = CallbackIOWrapper(upload_pbar.update, infile, "read")
480-
files = {"file": (os.path.basename(ingress_path), wrapped_file, "application/octet-stream")}
481-
response = requests.put(s3_ingress_url, files=files, headers=headers)
484+
#files = {"file": (os.path.basename(ingress_path), wrapped_file, "application/octet-stream")}
485+
#response = requests.put(s3_ingress_url, files=files, headers=headers)
486+
response = requests.put(s3_ingress_url, data=wrapped_file, headers=headers)
482487
response.raise_for_status()
483488

484489
logger.info("Batch %d : %s Ingest complete", batch_index, trimmed_path)
485490
update_summary_table(SUMMARY_TABLE, "uploaded", ingress_path)
491+
upload_pbar.reset()
486492
elif response_result == HTTPStatus.NO_CONTENT:
487493
logger.info(
488494
"Batch %d : Skipping ingress for %s, reason %s", batch_index, trimmed_path, ingress_response.get("message")
@@ -529,6 +535,8 @@ def ingress_multipart_file_to_s3(ingress_response, batch_index, batch_pbar):
529535
If an unexpected response is received from the Ingress Lambda app.
530536
531537
"""
538+
global SUMMARY_TABLE
539+
532540
logger = get_logger("ingress_multipart_file_to_s3", console=False)
533541

534542
response_result = int(ingress_response.get("result", -1))

src/pds/ingress/util/report_util.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
99
"""
1010
import json
11+
import multiprocessing
1112
import os
1213
import time
1314
from datetime import datetime
1415
from datetime import timezone
1516

1617
from pds.ingress.util.log_util import get_logger
1718

19+
REPORT_SEMAPHORE = multiprocessing.Semaphore(1)
20+
"""Semaphore used to control write access to Batch progress bars"""
21+
1822
EXPECTED_MANIFEST_KEYS = ("ingress_path", "md5", "size", "last_modified")
1923
"""The keys we expect to find assigned to each mapping within a read manifest"""
2024

@@ -57,18 +61,19 @@ def update_summary_table(summary_table, key, paths):
5761
if not isinstance(paths, list):
5862
paths = [paths]
5963

60-
summary_table[key].update(paths)
64+
with REPORT_SEMAPHORE:
65+
summary_table[key].update(paths)
6166

62-
if key == "uploaded":
63-
# Update total number of bytes transferrred for successful uploads
64-
summary_table["transferred"] += sum(os.stat(path).st_size for path in paths)
67+
if key == "uploaded":
68+
# Update total number of bytes transferrred for successful uploads
69+
summary_table["transferred"] += sum(os.stat(path).st_size for path in paths)
6570

66-
# If this file or files previous failed, remove from the failed set
67-
summary_table["failed"] -= set(paths)
71+
# If this file or files previous failed, remove from the failed set
72+
summary_table["failed"] -= set(paths)
6873

69-
# Prune any now-visted paths from the unprocessed set
70-
if key != "unprocessed":
71-
summary_table["unprocessed"] -= set(paths)
74+
# Prune any now-visted paths from the unprocessed set
75+
if key != "unprocessed":
76+
summary_table["unprocessed"] -= set(paths)
7277

7378

7479
def print_ingress_summary(summary_table):

0 commit comments

Comments
 (0)