def get(cls, run_id: str) -> 'Run': try: resp = session.get(f'{cls.endpoint_uri()}/run/{run_id}') resp.raise_for_status() return Run.from_dict(resp.json()) except HTTPError: cls.logger.debug('HttpError', exc_info=True) raise ValueError('Failed to find the run in the task store.') except (json.JSONDecodeError, TypeError): cls.logger.debug('JsonError', exc_info=True) raise ValueError('Failed to deserialize the response content.')
def get(cls, task_id: str) -> 'Task': try: resp = session.get(f'{cls.endpoint_uri()}/task/{task_id}') resp.raise_for_status() return Task.from_dict(resp.json()) except requests.HTTPError as error: cls.logger.debug('HttpError', exc_info=True) if error.response.status_code == 404: raise ValueError(f'Task {task_id} is not found.') raise ValueError('Fail to get runs.') except (KeyError, json.JSONDecodeError, TypeError): cls.logger.debug('JsonError', exc_info=True) raise ValueError('Fail to parse the runs data.')
def get(cls, run_id: str) -> 'TaskCollection': try: resp = session.get(f'{cls.endpoint_uri()}/run/{run_id}/tasks') resp.raise_for_status() tasks = [Task.from_dict(each) for each in resp.json()] return TaskCollection(tasks=tasks, run_id=run_id) except HTTPError as error: cls.logger.debug('HttpError', exc_info=True) if error.response.status_code == 404: raise ValueError(f'Run {run_id} is not found.') raise ValueError('Fail to get runs.') except (KeyError, json.JSONDecodeError, TypeError): cls.logger.debug('JsonError', exc_info=True) raise ValueError('Fail to parse the runs data.')
def get(cls, **kwargs) -> 'RunCollection': try: url = f'{cls.endpoint_uri()}/runs' query = {} for key, value in kwargs.items(): if value is not None: query[key] = value if query: url = f'{url}?{urllib.parse.urlencode(query)}' resp = session.get(url) resp.raise_for_status() runs = [Run.from_dict(each) for each in resp.json()] runs = sorted(runs, key=lambda r: r.id, reverse=True) return RunCollection(runs) except HTTPError: cls.logger.debug('HttpError', exc_info=True) raise ValueError('Fail to get runs.') except (KeyError, json.JSONDecodeError, TypeError): cls.logger.debug('JsonError', exc_info=True) raise ValueError('Fail to parse the runs data.')
def _check_task_store_healthy(store_ip: str) -> None: resp = session.get(f'http://{store_ip}/healthy') resp.raise_for_status() if json.loads(resp.content.decode('utf-8'))['status'] != 'healthy': raise ValueError()