Skip to content

Commit

Permalink
log the user storage stats periodically and on upload ops
Browse files Browse the repository at this point in the history
  • Loading branch information
jheld committed Sep 15, 2023
1 parent 88941ab commit a01ca8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions diycrate/item_queue_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from boxsdk.object.event import Event
from boxsdk.object.file import File
from boxsdk.object.folder import Folder
from boxsdk.object.user import User
from dateutil.parser import parse
from dateutil.tz import tzutc
from requests.exceptions import ConnectionError
Expand Down Expand Up @@ -109,13 +110,13 @@ def perform_upload(
if isinstance(ret_val, tuple):
ret_val, post_ret_callable = ret_val
crate_logger.info(
f"Completed upload{' ' + explicit_file_path if was_list else ''}"
f"Completed upload/operation/{' ' + explicit_file_path if was_list else ''}"
)
if was_list:
path_name = explicit_file_path
item = ret_val # is the new/updated item
client = Client(oauth)
if isinstance(item, File):
client = Client(oauth)
file_obj: File = client.file(file_id=item.object_id).get(
fields=["path_collection", "name", "etag", "modified_at"]
)
Expand Down Expand Up @@ -154,6 +155,14 @@ def perform_upload(
)
if isinstance(post_ret_callable, partial):
post_ret_callable()
user_resource: User = client.user()
user: User = user_resource.get(fields=["space_used", "space_amount"])
crate_logger.debug(
"User space used/amount: %d%% -> (used: %dGiB, total: %dGiB)",
(user.space_used / user.space_amount) * 100,
user.space_used / 1024 / 1024 / 1024,
user.space_amount / 1024 / 1024 / 1024,
)
break
except BoxAPIException as e:
crate_logger.info(f"{args}", exc_info=True)
Expand Down
9 changes: 9 additions & 0 deletions diycrate/path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from typing import Union, Optional, Dict, List

from boxsdk.object.user import User
from dateutil.tz import tzutc
from bottle import Bottle
from boxsdk import OAuth2
Expand Down Expand Up @@ -75,6 +76,14 @@ def walk_and_notify_and_download_tree(
if Path(path) == BOX_DIR:
for mkey, mvalue in time_data_map.items():
r_c.set(local_or_box_file_m_time_key_func(mkey, False), mvalue)
user_resource: User = client.user()
user: User = user_resource.get(fields=["space_used", "space_amount"])
crate_logger.info(
"Walking in root dir, user space used/amount: %d%% -> (used: %dGiB, total: %dGiB)",
(user.space_used / user.space_amount) * 100,
user.space_used / 1024 / 1024 / 1024,
user.space_amount / 1024 / 1024 / 1024,
)
while True:
try:
basic_folder_keys = ["id", "etag", "name", "path_collection", "modified_at"]
Expand Down

0 comments on commit a01ca8a

Please sign in to comment.