4646from pds .ingress .util .report_util import parts_to_xml
4747from pds .ingress .util .report_util import print_ingress_summary
4848from pds .ingress .util .report_util import read_manifest_file
49+ from pds .ingress .util .report_util import update_summary_table
4950from pds .ingress .util .report_util import write_manifest_file
5051from requests .exceptions import RequestException
5152from tqdm .utils import CallbackIOWrapper
@@ -165,6 +166,8 @@ def _process_batch(batch_index, request_batch, node_id, force_overwrite, api_gat
165166 fully processed.
166167
167168 """
169+ global SUMMARY_TABLE # noqa: F824
170+
168171 logger = get_logger ("_process_batch" , console = False )
169172
170173 # Get an avaialble Batch progress bar to update while iterating through this
@@ -191,7 +194,8 @@ def _process_batch(batch_index, request_batch, node_id, force_overwrite, api_gat
191194 except RequestException as err :
192195 # If here, the HTTP request error was unrecoverable by a backoff/retry
193196 trimmed_path = ingress_response .get ("trimmed_path" )
194- SUMMARY_TABLE ["failed" ][batch_index ].add (trimmed_path )
197+ ingress_path = ingress_response .get ("ingress_path" )
198+ update_summary_table (SUMMARY_TABLE , "failed" , ingress_path )
195199
196200 logger .error (
197201 "Batch %d : Ingress failed for %s, HTTP code: %s\n HTTP response text:\n %s" ,
@@ -455,18 +459,19 @@ def ingress_file_to_s3(ingress_response, batch_index, batch_pbar):
455459 If an unexpected response is received from the Ingress Lambda app.
456460
457461 """
462+ global SUMMARY_TABLE # noqa: F824
463+
458464 logger = get_logger ("ingress_file_to_s3" , console = False )
459465
460466 response_result = int (ingress_response .get ("result" , - 1 ))
461467 trimmed_path = ingress_response .get ("trimmed_path" )
468+ ingress_path = ingress_response .get ("ingress_path" )
462469
463470 if response_result == HTTPStatus .OK :
464471 s3_ingress_url = ingress_response .get ("s3_url" )
465472
466473 logger .info ("Batch %d : Ingesting %s to %s" , batch_index , trimmed_path , s3_ingress_url .split ("?" )[0 ])
467474
468- ingress_path = ingress_response .get ("ingress_path" )
469-
470475 if not ingress_path :
471476 raise ValueError ("No ingress path provided with response for %s" , trimmed_path )
472477
@@ -496,25 +501,24 @@ def ingress_file_to_s3(ingress_response, batch_index, batch_pbar):
496501 response .raise_for_status ()
497502
498503 logger .info ("Batch %d : %s Ingest complete" , batch_index , trimmed_path )
499- SUMMARY_TABLE ["uploaded" ][batch_index ].add (trimmed_path )
500-
501- # Update total number of bytes transferrred
502- SUMMARY_TABLE ["transferred" ] += os .stat (ingress_path ).st_size
504+ update_summary_table (SUMMARY_TABLE , "uploaded" , ingress_path )
505+ upload_pbar .reset ()
503506 elif response_result == HTTPStatus .NO_CONTENT :
504507 logger .info (
505508 "Batch %d : Skipping ingress for %s, reason %s" , batch_index , trimmed_path , ingress_response .get ("message" )
506509 )
507- SUMMARY_TABLE [ "skipped" ][ batch_index ]. add ( trimmed_path )
510+ update_summary_table ( SUMMARY_TABLE , "skipped" , ingress_path )
508511 elif response_result == HTTPStatus .NOT_FOUND :
509512 logger .warning (
510513 "Batch %d : Ingress failed for %s, reason: %s" , batch_index , trimmed_path , ingress_response .get ("message" )
511514 )
512- SUMMARY_TABLE [ "failed" ][ batch_index ]. add ( trimmed_path )
515+ update_summary_table ( SUMMARY_TABLE , "failed" , ingress_path )
513516 else :
514517 logger .error ("Batch %d : Unexepected response code (%d) from Ingress service" , batch_index , response_result )
515518 raise RuntimeError
516519
517520
521+ # noinspection PyUnreachableCode
518522@backoff .on_exception (
519523 backoff .expo ,
520524 Exception ,
@@ -545,15 +549,17 @@ def ingress_multipart_file_to_s3(ingress_response, batch_index, batch_pbar):
545549 If an unexpected response is received from the Ingress Lambda app.
546550
547551 """
552+ global SUMMARY_TABLE # noqa: F824
553+
548554 logger = get_logger ("ingress_multipart_file_to_s3" , console = False )
549555
550556 response_result = int (ingress_response .get ("result" , - 1 ))
551557 trimmed_path = ingress_response .get ("trimmed_path" )
558+ ingress_path = ingress_response .get ("ingress_path" )
552559
553560 if response_result == HTTPStatus .OK :
554561 logger .info ("Batch %d : Performing Multipart Upload for %s" , batch_index , trimmed_path )
555562
556- ingress_path = ingress_response .get ("ingress_path" )
557563 s3_ingress_urls = ingress_response .get ("s3_urls" , [])
558564 upload_complete_url = ingress_response .get ("upload_complete_url" )
559565 upload_abort_url = ingress_response .get ("upload_abort_url" )
@@ -601,20 +607,17 @@ def ingress_multipart_file_to_s3(ingress_response, batch_index, batch_pbar):
601607 response .raise_for_status ()
602608
603609 logger .info ("Batch %d : %s Multipart Upload complete" , batch_index , trimmed_path )
604- SUMMARY_TABLE ["uploaded" ][batch_index ].add (trimmed_path )
605-
606- # Update total number of bytes transferrred
607- SUMMARY_TABLE ["transferred" ] += os .stat (ingress_path ).st_size
610+ update_summary_table (SUMMARY_TABLE , "uploaded" , ingress_path )
608611 elif response_result == HTTPStatus .NO_CONTENT :
609612 logger .info (
610613 "Batch %d : Skipping ingress for %s, reason %s" , batch_index , trimmed_path , ingress_response .get ("message" )
611614 )
612- SUMMARY_TABLE [ "skipped" ][ batch_index ]. add ( trimmed_path )
615+ update_summary_table ( SUMMARY_TABLE , "skipped" , ingress_path )
613616 elif response_result == HTTPStatus .NOT_FOUND :
614617 logger .warning (
615618 "Batch %d : Ingress failed for %s, reason: %s" , batch_index , trimmed_path , ingress_response .get ("message" )
616619 )
617- SUMMARY_TABLE [ "failed" ][ batch_index ]. add ( trimmed_path )
620+ update_summary_table ( SUMMARY_TABLE , "failed" , ingress_path )
618621 else :
619622 logger .error ("Batch %d : Unexepected response code (%d) from Ingress service" , batch_index , response_result )
620623 raise RuntimeError
@@ -789,17 +792,24 @@ def main(args):
789792 with get_path_progress_bar (args .ingress_paths ) as pbar :
790793 resolved_ingress_paths = PathUtil .resolve_ingress_paths (args .ingress_paths , pbar )
791794
795+ # Initialize the summary table, and populate the "unprocessed" table the set
796+ # of resolved ingress paths
797+ SUMMARY_TABLE = initialize_summary_table ()
798+ update_summary_table (SUMMARY_TABLE , "unprocessed" , resolved_ingress_paths )
799+
792800 node_id = args .node
793801
794802 # Set the joblib pool size based on the number of "threads" requested
795803 PARALLEL .n_jobs = args .num_threads
796804
797805 # Break the set of ingress paths into batches based on configured size
798806 batch_size = int (config ["OTHER" ].get ("batch_size" , fallback = 1 ))
807+ SUMMARY_TABLE ["batch_size" ] = batch_size
799808
800809 batched_ingress_paths = list (batched (resolved_ingress_paths , batch_size ))
801810 logger .info ("Using batch size of %d" , batch_size )
802811 logger .info ("Request (%d files) split into %d batches" , len (resolved_ingress_paths ), len (batched_ingress_paths ))
812+ SUMMARY_TABLE ["num_batches" ] = len (batched_ingress_paths )
803813
804814 if args .manifest_path and os .path .exists (args .manifest_path ):
805815 logger .info ("Reading existing manifest file %s" , args .manifest_path )
@@ -813,8 +823,6 @@ def main(args):
813823 write_manifest_file (MANIFEST , os .path .abspath (args .manifest_path ))
814824
815825 if not args .dry_run :
816- SUMMARY_TABLE = initialize_summary_table ()
817-
818826 cognito_config = config ["COGNITO" ]
819827
820828 # TODO: add support for command-line username/password?
@@ -848,23 +856,21 @@ def main(args):
848856 finally :
849857 close_batch_progress_bars ()
850858
851- # Capture completion time of transfer and batch configuration
852- SUMMARY_TABLE ["end_time" ] = time .time ()
853- SUMMARY_TABLE ["batch_size" ] = batch_size
854- SUMMARY_TABLE ["num_batches" ] = len (batched_ingress_paths )
855-
856- # Create the JSON report file, if requested
857- if args .report_path :
858- create_report_file (args , SUMMARY_TABLE )
859-
860- # Print the summary table
861- print_ingress_summary (SUMMARY_TABLE )
862-
863859 # Flush all logged statements to CloudWatch Logs
864860 log_util .CLOUDWATCH_HANDLER .flush ()
865861 else :
866862 logger .info ("Dry run requested, skipping ingress request submission." )
867863
864+ # Capture completion time
865+ SUMMARY_TABLE ["end_time" ] = time .time ()
866+
867+ # Create the JSON report file, if requested
868+ if args .report_path :
869+ create_report_file (args , SUMMARY_TABLE )
870+
871+ # Print the summary table
872+ print_ingress_summary (SUMMARY_TABLE )
873+
868874
869875def console_main ():
870876 """No argument entrypoint for use with setuptools"""
0 commit comments