Skip to content

Commit

Permalink
include client_version in job requests, rename field from assign to c…
Browse files Browse the repository at this point in the history
…lient
  • Loading branch information
tykling committed Nov 10, 2024
1 parent c5f4125 commit 7e1c28b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/bma_client_lib/bma_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import httpx
import magic
from PIL import Image, ImageOps
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version


logger = logging.getLogger("bma_client")

Expand All @@ -27,6 +30,12 @@
# maybe these should come from server settings
SKIP_EXIF_TAGS = ["JPEGThumbnail", "TIFFThumbnail", "Filename"]

# get version
try:
__version__ = version("bma-client-lib")
except PackageNotFoundError:
__version__ = "0.0.0"


class BmaBearerAuth(httpx.Auth):
"""An httpx.Auth subclass to add Bearer token to requests."""
Expand Down Expand Up @@ -62,6 +71,7 @@ def __init__(
self.path = path
self.skip_exif_tags = SKIP_EXIF_TAGS
self.get_server_settings()
self.__version__ = __version__

def update_access_token(self) -> None:
"""Set or update self.access_token using self.refresh_token."""
Expand Down Expand Up @@ -119,7 +129,10 @@ def get_job_assignment(self, file_uuid: uuid.UUID | None = None) -> list[dict[st
url = self.base_url + "/api/v1/json/jobs/assign/"
if file_uuid:
url += f"?file_uuid={file_uuid}"
data = {"client_uuid": self.uuid}
data = {
"client_uuid": self.uuid,
"client_version": "bma-client-lib {__version__}",
}
try:
r = self.client.post(url, json=data).raise_for_status()
response = r.json()["bma_response"]
Expand Down Expand Up @@ -277,11 +290,12 @@ def upload_job_result(self, job_uuid: uuid.UUID, buf: "BytesIO", filename: str)
# build metadata
data = {
"client_uuid": self.uuid,
"client_version": "bma-client-lib {__version__}",
}
# doit
r = self.client.post(
self.base_url + f"/api/v1/json/jobs/{job_uuid}/result/",
data={"assign": json.dumps(data)},
data={"client": json.dumps(data)},
files=files,
).raise_for_status()
t = time.time() - start
Expand Down

0 comments on commit 7e1c28b

Please sign in to comment.