@@ -307,8 +307,9 @@ def filter_exports(self, common_diffs: FileDiffMap):
307307 else :
308308 replace (diff_file , exported_file )
309309
310- def run (self ):
310+ def run (self , logger = None ):
311311 """Run the differ and archive the changed and new files."""
312+ start_time = time .time ()
312313 self .update_cache ()
313314
314315 # Diff exports, and make incremental versions
@@ -317,6 +318,11 @@ def run(self):
317318 # Archive changed and new files only
318319 to_archive = [f for f , diff in common_diffs .items ()
319320 if diff is not None ]
321+ if logger :
322+ logger .debug ("Diffed exports" ,
323+ phase = "archiving" ,
324+ new_files_count = len (new_files ),
325+ common_diffs_count = len (to_archive ))
320326 to_archive += new_files
321327 _ , fails = self .archive_exports (to_archive )
322328
@@ -329,6 +335,14 @@ def run(self):
329335 for exported_file in fails :
330336 print (f"Failed to archive '{ exported_file } '" )
331337
338+ elapsed_time_in_seconds = round (time .time () - start_time , 2 )
339+ if logger :
340+ logger .info ("Completed archive run" ,
341+ phase = "archiving" ,
342+ elapsed_time_in_seconds = elapsed_time_in_seconds ,
343+ new_changed_count = len (to_archive ),
344+ fail_count = len (fails ))
345+
332346
333347class S3ArchiveDiffer (ArchiveDiffer ):
334348 """
@@ -641,8 +655,23 @@ def archive_exports(self, exported_files):
641655 successes: All files from input
642656 fails: Empty list
643657 """
658+ archive_success , archive_fail = [], []
659+ for exported_file in exported_files :
660+ archive_file = abspath (
661+ join (self .cache_dir , basename (exported_file )))
662+
663+ # Copy export to cache
664+ try :
665+ # Archive
666+ shutil .copyfile (exported_file , archive_file )
667+ archive_success .append (exported_file )
668+
669+ except FileNotFoundError as ex :
670+ print (ex )
671+ archive_fail .append (exported_file )
672+
644673 self ._exports_archived = True
645- return exported_files , []
674+ return archive_success , archive_fail
646675
647676 def update_cache (self ):
648677 """Handle cache updates with a no-op.
@@ -667,13 +696,6 @@ def update_cache(self):
667696 if "archive" not in _params :
668697 _params = {"archive" : _params , "common" : _params }
669698
670- logger = get_structured_logger (
699+ archiver_from_params ( _params ). run ( get_structured_logger (
671700 __name__ , filename = _params ["common" ].get ("log_filename" ),
672- log_exceptions = _params ["common" ].get ("log_exceptions" , True ))
673- start_time = time .time ()
674-
675- archiver_from_params (_params ).run ()
676-
677- elapsed_time_in_seconds = round (time .time () - start_time , 2 )
678- logger .info ("Completed archive run." ,
679- elapsed_time_in_seconds = elapsed_time_in_seconds )
701+ log_exceptions = _params ["common" ].get ("log_exceptions" , True )))
0 commit comments