async def invoke_single(self, request_item: Query) -> Any: logger.debug("Replica {} started executing request {}".format( self.replica_tag, request_item.metadata.request_id)) args, kwargs = parse_request_item(request_item) start = time.time() method_to_call = None try: runner_method = self.get_runner_method(request_item) method_to_call = sync_to_async(runner_method) result = None if len(inspect.signature(runner_method).parameters) > 0: result = await method_to_call(*args, **kwargs) else: # The method doesn't take in anything, including the request # information, so we pass nothing into it result = await method_to_call() result = await self.ensure_serializable_response(result) self.request_counter.inc() except Exception as e: import os if "RAY_PDB" in os.environ: ray.util.pdb.post_mortem() function_name = "unknown" if method_to_call is not None: function_name = method_to_call.__name__ result = wrap_to_ray_error(function_name, e) self.error_counter.inc() latency_ms = (time.time() - start) * 1000 self.processing_latency_tracker.observe(latency_ms) return result
async def invoke_single(self, request_item: Query) -> Tuple[Any, bool]: """Executes the provided request on this replica. Returns the user-provided output and a boolean indicating if the request succeeded (user code didn't raise an exception). """ logger.debug( "Replica {} started executing request {}".format( self.replica_tag, request_item.metadata.request_id ) ) args, kwargs = parse_request_item(request_item) method_to_call = None success = True try: runner_method = self.get_runner_method(request_item) method_to_call = sync_to_async(runner_method) result = None if len(inspect.signature(runner_method).parameters) > 0: result = await method_to_call(*args, **kwargs) else: # When access via http http_arg_is_pickled with no args: # args = (<starlette.requests.Request object at 0x7fe900694cc0>,) # When access via python with no args: # args = () if len(args) == 1 and isinstance(args[0], starlette.requests.Request): # The method doesn't take in anything, including the request # information, so we pass nothing into it result = await method_to_call() else: # Will throw due to signature mismatch if user attempts to # call with non-empty args result = await method_to_call(*args, **kwargs) result = await self.ensure_serializable_response(result) self.request_counter.inc() except Exception as e: logger.exception(f"Request failed due to {type(e).__name__}:") success = False if "RAY_PDB" in os.environ: ray.util.pdb.post_mortem() function_name = "unknown" if method_to_call is not None: function_name = method_to_call.__name__ result = wrap_to_ray_error(function_name, e) self.error_counter.inc() return result, success