def get_task_status(self, task_id): response = requests.get("{}/task/{}/status".format(self.url, task_id), timeout=self._timeout) if response.ok: return response.json()["status"] else: response.raise_for_status()
def shutdown(self): response = requests.post("{}/shutdown".format(self.url), timeout=self._timeout) if response.ok: return response.json() else: response.raise_for_status()
def get_tasks(self): response = requests.get("{}/task".format(self.url), timeout=self._timeout) if response.ok: return response.json()["tasks"] else: response.raise_for_status()
def stop_task(self, task_id): response = requests.post("{}/task/{}/stop".format(self.url, task_id), timeout=self._timeout) if response.ok: return response.json() else: response.raise_for_status()
def get_worker(self, kale_id): self.logger.debug("get_worker") response = requests.get("{}/worker/{}".format(self.url, kale_id), timeout=self._timeout) if response.ok: return response.json() else: response.raise_for_status()
async def _call_opener_service(endpoint: Text, data: Text) -> Text: async with _get_client_session(endpoint) as session: async with session.post(endpoint, data={'input': data}) as response: try: response.raise_for_status() except ClientError as ex: raise ServerError('unable to call {} {}'.format(endpoint, ex)) else: return await response.text()
def list_workers(self): self.logger.debug("list_workers") response = requests.get("{}/worker".format(self.url), timeout=self._timeout) if response.ok: self.logger.debug(response.json()) return response.json() else: self.logger.debug("response {} {}".format(response.reason, response.text)) response.raise_for_status()
def upload_image(self, image): buffered = io.BytesIO() image.save(buffered, format="JPEG") image_bytes = buffered.getvalue() file_list = {"file": image_bytes} headers = {'key': IMAGE_UPLOAD_SERVER_KEY} response = requests.post(IMAGE_UPLOAD_SERVER_URL, headers=headers, files=file_list) response.raise_for_status() return f"![]({response.text})"
def get_status(self): self.logger.debug("status") response = requests.get("{}/status".format(self.url), timeout=self._timeout) if response.ok: msg = response.json() if "status" in msg: return msg["status"] elif "error" in msg: self.logger.debug(msg["error"]) else: response.raise_for_status()
def add_worker(self, kale_id, protocol, host, port): self.logger.debug("add_worker") response = requests.post("{}/worker".format(self.url), timeout=self._timeout, body={ "id": kale_id, "protocol": protocol, "host": host, "port": port }) if response.ok: return response.json() else: response.raise_for_status()
def get_task_output(self, task_id): response = requests.get("{}/task/{}/results".format(self.url, task_id), timeout=self._timeout) if response.ok: raw_output = response.json() try: output = pickle.loads(bytes(raw_output["results"])) except KeyError: raise Exception(response.json()) return output else: raise response.raise_for_status()