Esempio n. 1
0
 async def __call_sync(self,
                       task,
                       outputs,
                       idx,
                       limiter,
                       max_retries=1,
                       pass_fail_job=False):
     if limiter is not None:
         async with limiter:
             for retry_idx in range(max_retries):
                 try:
                     outputs[idx] = task()
                     self.update_progress_bar()
                     return None
                 except Exception:
                     if retry_idx == max_retries - 1 and not pass_fail_job:
                         with except_handler():
                             raise AssertionError(
                                 "ERROR in {}th task.\n {1}".format(
                                     idx,
                                     format_exc(
                                         name="mlchain.workflows.parallel")
                                 ))
                     if retry_idx < max_retries - 1 or not self.verbose:
                         logger.error(
                             "PARALLEL ERROR in {0}th task and retry task,"
                             " run times = {1}".format(idx, retry_idx + 1))
                     else:
                         logger.debug(
                             "PASSED PARALLEL ERROR in {}th task:".format(
                                 idx,
                                 format_exc(
                                     name="mlchain.workflows.parallel")))
     else:
         for retry_idx in range(max_retries):
             try:
                 outputs[idx] = task()
                 self.update_progress_bar()
                 return None
             except Exception:
                 if retry_idx == max_retries - 1 and not pass_fail_job:
                     with except_handler():
                         raise AssertionError("ERROR in {}th task\n".format(
                             idx,
                             format_exc(name="mlchain.workflows.parallel")))
                 if retry_idx < max_retries - 1 or not self.verbose:
                     logger.error(
                         "PARALLEL ERROR in {0}th task and retry task,"
                         " run times = {1}".format(idx, retry_idx + 1))
                 else:
                     logger.debug("PASSED PARALLEL ERROR: {0}".format(
                         format_exc(name="mlchain.workflows.parallel")))
     self.update_progress_bar()
Esempio n. 2
0
    def __init__(self, api_key=None, api_address=None, serializer='msgpack',
                 image_encoder=None, name=None, version='lastest',
                 check_status=False, headers=None, **kwargs):
        MLClient.__init__(self, api_key=api_key, api_address=api_address,
                          serializer=serializer, image_encoder=image_encoder,
                          name=name, version=version,
                          check_status=check_status, headers=headers, **kwargs)
        if isinstance(self.api_address, str):
            self.api_address = self.api_address.strip()
            if len(self.api_address) > 0 and self.api_address[-1] == '/':
                self.api_address = self.api_address[:-1]

            if len(self.api_address) > 0 and self.api_address[0] != 'h':
                self.api_address = 'http://{0}'.format(api_address)

        self.content_type = 'application/{0}'.format(self.serializer_type)
        if check_status:
            try:
                ping = self.get('ping', timeout=5)
                logger.info("Connected to server {0}: {1}".format(api_address, ping))
            except Exception as e:
                logger.info("Can't connect to server {0}: {1}".format(api_address, e))
            output_description = self.get('description', timeout=20)
            if 'error' in output_description:
                with except_handler():
                    raise AssertionError("ERROR: Model {0} in version {1} is not found".format(
                        name,
                        version))
            else:
                output_description = output_description['output']
                self.__doc__ = output_description['__main__']
                self.all_func_des = output_description['all_func_des']
                self.all_func_params = output_description['all_func_params']
                self.all_attributes = output_description['all_attributes']
Esempio n. 3
0
    def __call__(self, *args, **kwargs):
        output = self.client.post(function_name=self.function_name,
                                  args=args,
                                  kwargs=kwargs)
        if isinstance(output, RawResponse):
            return output.value
        output = self.serializer.decode(output)
        if 'error' in output:
            with except_handler():
                raise Exception(
                    "MLCHAIN VERSION: {} \n API VERSION: {} \n ERROR_CODE: {} \n INFO_ERROR: {}, "
                    .format(output.get('mlchain_version', None),
                            output.get('api_version', None),
                            output.get('code', None), output['error']))

        return output['output']