Skip to content

Commit cd21ba6

Browse files
committed
Address PR comments
1 parent 54e0dab commit cd21ba6

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

simvue/api/objects/artifact/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pathlib
77
import shutil
88
from simvue.config.user import SimvueConfiguration
9-
import uuid
9+
from datetime import datetime
1010
from simvue.models import NAME_REGEX
1111
from simvue.utilities import get_mimetype_for_file, get_mimetypes, calculate_sha256
1212

@@ -87,7 +87,7 @@ def new(
8787
)
8888
_local_staging_dir.mkdir(parents=True, exist_ok=True)
8989
_local_staging_file = _local_staging_dir.joinpath(
90-
f"{uuid.uuid4()}.file"
90+
f"{file_path.stem}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S_%f')[:-3]}.file"
9191
)
9292
shutil.copy(file_path, _local_staging_file)
9393
file_path = _local_staging_file

simvue/sender.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import requests
1414
import psutil
1515
from simvue.config.user import SimvueConfiguration
16-
1716
import simvue.api.objects
1817
from simvue.api.objects.artifact.base import ArtifactBase
1918
from simvue.eco.emissions_monitor import CO2Monitor
@@ -37,11 +36,18 @@
3736
_logger = logging.getLogger(__name__)
3837

3938

40-
def _log_upload_failed(file_path):
41-
with open(file_path, "r") as file:
39+
def _log_upload_failed(file_path: pydantic.FilePath) -> None:
40+
"""Record that an object failed to upload in the object offline cache file.
41+
42+
Parameters
43+
----------
44+
file_path : pydantic.FilePath
45+
The path to the offline cache file for the object
46+
"""
47+
with file_path.open("r") as file:
4248
_data = json.load(file)
4349
_data["upload_failed"] = True
44-
with open(file_path, "w") as file:
50+
with file_path.open("w") as file:
4551
json.dump(_data, file)
4652

4753

@@ -52,7 +58,7 @@ def upload_cached_file(
5258
id_mapping: dict[str, str],
5359
retry_failed_uploads: bool,
5460
lock: threading.Lock,
55-
):
61+
) -> None:
5662
"""Upload data stored in a cached file to the Simvue server.
5763
5864
Parameters
@@ -228,12 +234,12 @@ def sender(
228234
if len(_offline_files) < threading_threshold:
229235
for file_path in _offline_files:
230236
upload_cached_file(
231-
cache_dir,
232-
_obj_type,
233-
file_path,
234-
_id_mapping,
235-
retry_failed_uploads,
236-
_lock,
237+
cache_dir=cache_dir,
238+
obj_type=_obj_type,
239+
file_path=file_path,
240+
id_mapping=_id_mapping,
241+
retry_failed_uploads=retry_failed_uploads,
242+
lock=_lock,
237243
)
238244
else:
239245
with ThreadPoolExecutor(

0 commit comments

Comments
 (0)