Skip to content

Commit

Permalink
Build: log directory size to be uploaded (#10779)
Browse files Browse the repository at this point in the history
* Build: log directory size to be uploaded

Ref readthedocs/meta#129

* Add example
  • Loading branch information
stsewd authored Sep 28, 2023
1 parent f88a4d6 commit 88f6c57
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import signal
import socket
import subprocess
from dataclasses import dataclass, field

import structlog
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88f6c57

Please sign in to comment.