Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions maestro_worker_python/upload_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
import logging
import tempfile
import threading
Expand All @@ -9,6 +8,7 @@
from os.path import join
from typing import List, Any

import orjson
import requests


Expand All @@ -24,11 +24,10 @@ def upload_files(upload_files: List[UploadFile]):
threads_upload = []
did_raise_exception = threading.Event()
for file_ in upload_files:
t = threading.Thread(target=_upload, args=(
file_, did_raise_exception,))
t = threading.Thread(target=_upload, args=(file_, did_raise_exception))
threads_upload.append(t)
t.start()

for t in threads_upload:
t.join()

Expand All @@ -40,7 +39,9 @@ def _upload(upload_file: UploadFile, did_raise_exception):
logging.info(f"Uploading:{upload_file.file_path}")
try:
with open(upload_file.file_path, "rb") as data:
response = requests.put(upload_file.signed_url, data=data, headers={"Content-Type": upload_file.file_type}, timeout=300)
response = requests.put(
upload_file.signed_url, data=data, headers={"Content-Type": upload_file.file_type}, timeout=300
)
response.raise_for_status()
logging.info(f"Uploaded {upload_file.file_path}")
except Exception as e:
Expand All @@ -60,8 +61,8 @@ def upload_json_data(upload_data: list[UploadJsonData]):

with tempfile.TemporaryDirectory() as tmp_dir:
for i, upload in enumerate(upload_data):
with open(join(tmp_dir, f"{i}.json"), "w") as tmp_file:
json.dump(upload.data, tmp_file)
with open(join(tmp_dir, f"{i}.json"), "wb") as tmp_file:
tmp_file.write(orjson.dumps(upload.data, option=orjson.OPT_SERIALIZE_NUMPY))
tmp_file.flush()
files_to_upload.append(
UploadFile(file_path=tmp_file.name, signed_url=upload.signed_url, file_type="application/json")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maestro-worker-python"
version = "3.5.1"
version = "3.5.2"
description = "Utility to run workers on Moises/Maestro"
authors = ["Moises.ai"]
license = "MIT"
Expand All @@ -15,6 +15,7 @@ json-logging = "^1.3.0"
uvicorn = "^0.20"
sentry-sdk = {extras = ["fastapi"], version = "^1.16.0"}
requests = "2.31.0"
orjson = "3.10.5"


[tool.poetry.group.dev.dependencies]
Expand Down