def untag(self): try: DockerCompass().get_api().remove_image(self.target) except Exception as e: LOG.error(e) return False else: return True
def _print_cell_output(self, out): dyct = out.dict() if dyct.get('output_type') == 'error': ename, evalue = dyct.get('ename', ''), dyct.get('evalue', '') LOG.error('{}: {}'.format(ename, evalue)) else: text = dyct.get('text', '') LOG.echo(text.strip())
def show_exception(cls, exception, callback=None): if isinstance(exception, PrettyError): exc = exception.pretty() else: exc = PrettyError.parse_exc(exception) if callable(callback): detail = callback(exception) LOG.info(detail) LOG.error(exc)
def _save_output(self, note_path, output_path): try: LOG.info("Saving output notebook: {}".format(output_path)) # TODO: convert to pdf (find a light-weight lib for that) NotebookBarrel(proj=self.proj, notebook=note_path, file_name=output_path).store_from_path(os.getcwd()) except Exception as e: err = NhaStorageError( "Failed to save output notebook '{}'".format(output_path)) e.__cause__ = e LOG.error(err)
def _predict_route(self): out, err, code = {}, None, None kwargs = self.make_request_kwargs() try: out = self.make_result(**kwargs) code = OnlineConst.ReturnCode.OK except Exception as e: if isinstance(e, NhaDataError): err = e.pretty() code = OnlineConst.ReturnCode.BAD_REQUEST elif isinstance(e, (PrettyError, ServingError)): err = e.pretty() code = OnlineConst.ReturnCode.SERVER_ERROR self._health = False else: err = repr(e) code = OnlineConst.ReturnCode.NOT_IMPLEMENTED LOG.error(err) finally: if self._enrich: response = self._cleaner({ 'result': out, 'err': err, 'metadata': self.make_metadata(**kwargs) }) else: response = out or err if isinstance(response, (dict, list)): response = assert_json(response, encode=True, encoding=OnlineConst.DEFAULT_CHARSET) else: response = assert_str(response) return self.application.make_response(code, response)
def _print_exc(self, e: Exception): LOG.error("Notebook execution failed:") LOG.error(e) self.proc_mon.set_state(Task.State.FAILED)