Skip to content
Snippets Groups Projects
Commit 46f793ce authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Optional halt client on non-200 response

parent e11ec192
No related branches found
No related tags found
No related merge requests found
......@@ -84,19 +84,24 @@ class FileBatchRunnerClient(HttpClient):
# iterate on files, assume all same directory
for fn in filelist:
self.input_acc_ids.append(
self.put(f'accessors/read_from_file/{fn}', query={'lazy': True})
self.put(f'accessors/read_from_file/{fn}', query={'lazy': True}).json()
)
def queue_tasks(self):
for k, v in self.conf['analyze']:
pass
for acc_id in self.input_acc_ids:
for v in self.conf['analyze']:
v['body']['schedule'] = True
v['body']['accessor_id'] = acc_id
self.hit(**v)
def run_tasks(self):
pass
self.put('tasks/run_all', query={'write_all': True})
# TODO: how to export data?
def run(self):
self.verify_server()
self.read_files()
self.setup()
\ No newline at end of file
self.setup()
self.queue_tasks()
self.run_tasks()
\ No newline at end of file
......@@ -9,8 +9,9 @@ class HttpClient(object):
app_name = 'model_server.base.api:app'
def __init__(self, host='127.0.0.1', port=6221) -> None:
def __init__(self, host='127.0.0.1', port=6221, raise_nonsuccess=False, **kwargs) -> None:
self.uri = f'http://{host}:{port}/'
self.raise_nonsuccess = raise_nonsuccess
def _get_sesh(self):
sesh = requests.Session()
......@@ -22,14 +23,20 @@ class HttpClient(object):
return sesh
def get(self, endpoint):
return self._get_sesh().get(self.uri + endpoint)
resp = self._get_sesh().get(self.uri + endpoint)
if self.raise_nonsuccess and resp.status_code != 200:
raise NonSuccessResposeError(resp.text)
return resp
def put(self, endpoint, query=None, body=None,):
return self._get_sesh().put(
resp = self._get_sesh().put(
self.uri + endpoint,
params=query,
data=json.dumps(body)
)
if self.raise_nonsuccess and resp.status_code != 200:
raise NonSuccessResponseError(resp.text)
return resp
def hit(self, method, endpoint, params=None, body=None):
"""
......@@ -46,4 +53,7 @@ class Error(Exception):
pass
class InvalidMethodError(Error):
pass
class NonSuccessResponseError(Error):
pass
\ No newline at end of file
......@@ -21,11 +21,19 @@ def parse_args():
default=8000,
help='bind socket to this port',
)
parser.add_argument(
'--raise_nonsuccess',
default=True,
help='raise a clientside exception if a response other than 200 is received',
)
return parser.parse_args()
def main(args):
client = FileBatchRunnerClient(conf_json=args.json, host=args.host, port=args.port)
client = FileBatchRunnerClient(
conf_json=args.json,
**args.__dict__,
)
client.run()
return
......
......@@ -24,11 +24,12 @@ cs = {
{
'description': 'Run segmentation with ilastik model',
'method': 'PUT',
'endpoint': 'chaeo/with_derived_channels/infer',
'endpoint': 'pipelines/roiset_to_obmap/infer',
'body': {
'api': False,
'keep_interm': True,
'model_id': 'px_seg_mod',
'pixel_classifier_segmentation_model_id': 'px_seg_mod',
'patches_channel': -1,
'channel': 0,
},
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment