From 88f6c571e5c5dd16986eff741c40c22f683765e2 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 28 Sep 2023 11:07:43 -0500 Subject: [PATCH] Build: log directory size to be uploaded (#10779) * Build: log directory size to be uploaded Ref https://github.com/readthedocs/meta/discussions/129 * Add example --- readthedocs/projects/tasks/builds.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/readthedocs/projects/tasks/builds.py b/readthedocs/projects/tasks/builds.py index b44a568c865..45be266988e 100644 --- a/readthedocs/projects/tasks/builds.py +++ b/readthedocs/projects/tasks/builds.py @@ -7,6 +7,7 @@ import os import signal import socket +import subprocess from dataclasses import dataclass, field import structlog @@ -912,6 +913,9 @@ def store_build_artifacts(self): include_file=False, version_type=self.data.version.type, ) + + self._log_directory_size(from_path, media_type) + try: build_media_storage.rclone_sync_directory(from_path, to_path) except Exception as exc: @@ -957,6 +961,25 @@ def store_build_artifacts(self): time=(timezone.now() - time_before_store_build_artifacts).seconds, ) + def _log_directory_size(self, directory, media_type): + try: + output = subprocess.check_output( + ["du", "--summarize", "--human-readable", "--", directory] + ) + # The output is something like: "1.2M\t/path/to/directory". + directory_size = output.decode().split()[0] + log.info( + "Build artifacts directory size.", + directory=directory, + size=directory_size, + media_type=media_type, + ) + except Exception: + log.info( + "Error getting build artifacts directory size.", + exc_info=True, + ) + def send_notifications(self, version_pk, build_pk, event): """Send notifications to all subscribers of `event`.""" # Try to infer the version type if we can