فهرست منبع

show run duration after each archived link in cli output

Nick Sweeting 4 سال پیش
والد
کامیت
62078a77f8
2فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 2 1
      archivebox/extractors/__init__.py
  2. 4 2
      archivebox/logging_util.py

+ 2 - 1
archivebox/extractors/__init__.py

@@ -96,6 +96,7 @@ def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[s
         log_link_archiving_started(link, out_dir, is_new)
         link = link.overwrite(updated=datetime.now(timezone.utc))
         stats = {'skipped': 0, 'succeeded': 0, 'failed': 0}
+        start_ts = datetime.now(timezone.utc)
 
         for method_name, should_run, method_function in ARCHIVE_METHODS:
             try:
@@ -142,7 +143,7 @@ def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[s
 
         write_link_details(link, out_dir=out_dir, skip_sql_index=False)
 
-        log_link_archiving_finished(link, link.link_dir, is_new, stats)
+        log_link_archiving_finished(link, link.link_dir, is_new, stats, start_ts)
 
     except KeyboardInterrupt:
         try:

+ 4 - 2
archivebox/logging_util.py

@@ -379,7 +379,7 @@ def log_link_archiving_started(link: "Link", link_dir: str, is_new: bool):
         pretty_path(link_dir),
     ))
 
-def log_link_archiving_finished(link: "Link", link_dir: str, is_new: bool, stats: dict):
+def log_link_archiving_finished(link: "Link", link_dir: str, is_new: bool, stats: dict, start_ts: datetime):
     total = sum(stats.values())
 
     if stats['failed'] > 0 :
@@ -390,7 +390,9 @@ def log_link_archiving_finished(link: "Link", link_dir: str, is_new: bool, stats
         _LAST_RUN_STATS.succeeded += 1
 
     size = get_dir_size(link_dir)
-    print('        {black}{} files ({}){reset}'.format(size[2], printable_filesize(size[0]), **ANSI))
+    end_ts = datetime.now(timezone.utc)
+    duration = str(end_ts - start_ts).split('.')[0]
+    print('        {black}{} files ({}) in {}s {reset}'.format(size[2], printable_filesize(size[0]), duration, **ANSI))
 
 
 def log_archive_method_started(method: str):