Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## v0.7.2

* Pydantic model is used for input validation.
* Support NaN, -inf and inf in metadata and metrics.

## v0.7.0

* Collect CPU, GPU and memory resource metrics.
Expand Down
2 changes: 1 addition & 1 deletion simvue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from simvue.client import Client
from simvue.handler import Handler
from simvue.models import RunInput
__version__ = '0.7.1'
__version__ = '0.7.2'
23 changes: 17 additions & 6 deletions simvue/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy
import json
import requests
from tenacity import retry, wait_exponential, stop_after_attempt

Expand All @@ -7,16 +9,25 @@
RETRY_MAX = 10
RETRY_STOP = 5

def set_json_header(headers):
"""
Return a copy of the headers with Content-Type set to
application/json
"""
headers = copy.deepcopy(headers)
headers['Content-Type'] = 'application/json'
return headers

@retry(wait=wait_exponential(multiplier=RETRY_MULTIPLIER, min=RETRY_MIN, max=RETRY_MAX),
stop=stop_after_attempt(RETRY_STOP))
def post(url, headers, data, is_json=True):
"""
HTTP POST with retries
"""
if is_json:
response = requests.post(url, headers=headers, json=data, timeout=DEFAULT_API_TIMEOUT)
else:
response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT)
data = json.dumps(data)
headers = set_json_header(headers)
response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT)

return response

Expand All @@ -27,8 +38,8 @@ def put(url, headers, data, is_json=True, timeout=DEFAULT_API_TIMEOUT):
HTTP PUT with retries
"""
if is_json:
response = requests.put(url, headers=headers, json=data, timeout=timeout)
else:
response = requests.put(url, headers=headers, data=data, timeout=timeout)
data = json.dumps(data)
headers = set_json_header(headers)
response = requests.put(url, headers=headers, data=data, timeout=timeout)

return response