jina.serve.executors.decorators module

Decorators and wrappers designed for wrapping BaseExecutor functions.

jina.serve.executors.decorators.wrap_func(cls, func_lst, wrapper)[source]

Wrapping a class method only once, inherited but not overridden method will not be wrapped again

  • cls – class

  • func_lst – function list to wrap

  • wrapper – the wrapper


Mark the args and kwargs of __init__() later to be stored via save_config() in YAML :type func: Callable :param func: the function to decorate :rtype: Callable :return: the wrapped function

jina.serve.executors.decorators.requests(func=None, *, on=None)[source]

@requests defines when a function will be invoked. It has a keyword on= to define the endpoint.

A class method decorated with plan @requests (without on=) is the default handler for all endpoints. That means, it is the fallback handler for endpoints that are not found.

  • func (Callable[[ForwardRef, Dict, ForwardRef, List[ForwardRef], List[ForwardRef]], Union[ForwardRef, Dict, None]]) – the method to decorate

  • on (Union[str, Sequence[str], None]) – the endpoint string, by convention starts with /


decorated function

jina.serve.executors.decorators.monitor(*, name=None, documentation=None)[source]

@monitor() allow to monitor internal method of your executor. You can access these metrics by enabling the monitoring on your Executor. It will track the time spend calling the function and the number of times it has been called. Under the hood it will create a prometheus Summary : https://prometheus.io/docs/practices/histograms/.


Don’t use this decorator with the @request decorator as it already handle monitoring under the hood

  • name (Optional[str]) – the name of the metrics, by default it is based on the name of the method it decorates

  • documentation (Optional[str]) – the description of the metrics, by default it is based on the name of the method it decorates


decorator which takes as an input a single callable