jina.serve.executors package

Submodules

Module contents

class jina.serve.executors.BaseExecutor(metas=None, requests=None, runtime_args=None, **kwargs)[source]

Bases: jina.jaml.JAMLCompatible

The base class of the executor, can be used to build encoder, indexer, etc.

Any executor inherited from BaseExecutor always has the meta defined in jina.executors.metas.defaults.

All arguments in the __init__() can be specified with a with map in the YAML config. Example:

class MyAwesomeExecutor:
    def __init__(awesomeness=5):
        pass

is equal to

jtype: MyAwesomeExecutor
with:
    awesomeness: 5

metas and requests are always auto-filled with values from YAML config.

Parameters
  • metas (Optional[Dict]) – a dict of metas fields

  • requests (Optional[Dict]) – a dict of endpoint-function mapping

  • runtime_args (Optional[Dict]) – a dict of arguments injected from Runtime during runtime

  • kwargs – additional extra keyword arguments to avoid failing when extra params ara passed that are not expected

close()[source]

Always invoked as executor is destroyed.

You can write destructor & saving logic here.

Return type

None

property workspace: Optional[str]

Get the workspace directory of the Executor.

Return type

Optional[str]

Returns

returns the workspace of the current shard of this Executor.

classmethod from_hub(uri, context=None, uses_with=None, uses_metas=None, uses_requests=None, **kwargs)[source]

Construct an Executor from Hub.

Parameters
  • uri (str) – a hub Executor scheme starts with jinahub://

  • context (Optional[Dict[str, Any]]) – context replacement variables in a dict, the value of the dict is the replacement.

  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • kwargs – other kwargs accepted by the CLI jina hub pull

Return type

~T

Returns

the Hub Executor object.

from jina import Executor
from docarray import Document, DocumentArray

executor = Executor.from_hub(
    uri='jinahub://CLIPImageEncoder', install_requirements=True
)
classmethod serve(uses_with=None, uses_metas=None, uses_requests=None, stop_event=None, **kwargs)[source]

Serve this Executor in a temporary Flow. Useful in testing an Executor in remote settings.

Parameters
  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • stop_event (Union[Event, Event, None]) – a threading event or a multiprocessing event that once set will resume the control Flow to main thread.

  • kwargs – other kwargs accepted by the Flow, full list can be found here <https://docs.jina.ai/api/jina.orchestrate.flow.base/>

class StandaloneExecutorType(value)[source]

Bases: jina.enums.BetterEnum

Type of standalone Executors

EXTERNAL = 0
SHARED = 1
static to_k8s_yaml(uses, output_base_path, k8s_namespace=None, executor_type=StandaloneExecutorType.EXTERNAL, uses_with=None, uses_metas=None, uses_requests=None, **kwargs)[source]

Converts the Executor into a set of yaml deployments to deploy in Kubernetes.

If you don’t want to rebuild image on Jina Hub, you can set JINA_HUB_NO_IMAGE_REBUILD environment variable.

Parameters
  • uses (str) – the Executor to use. Has to be containerized and accessible from K8s

  • output_base_path (str) – The base path where to dump all the yaml files

  • k8s_namespace (Optional[str]) – The name of the k8s namespace to set for the configurations. If None, the name of the Flow will be used.

  • executor_type (Optional[StandaloneExecutorType]) – The type of Executor. Can be external or shared. External Executors include the Gateway. Shared Executors don’t. Defaults to External

  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • kwargs – other kwargs accepted by the Flow, full list can be found here <https://docs.jina.ai/api/jina.orchestrate.flow.base/>

static to_docker_compose_yaml(uses, output_path=None, network_name=None, executor_type=StandaloneExecutorType.EXTERNAL, uses_with=None, uses_metas=None, uses_requests=None, **kwargs)[source]

Converts the Executor into a yaml file to run with docker-compose up :type uses: str :param uses: the Executor to use. Has to be containerized :type output_path: Optional[str] :param output_path: The output path for the yaml file :type network_name: Optional[str] :param network_name: The name of the network that will be used by the deployment name :type executor_type: Optional[StandaloneExecutorType] :param executor_type: The type of Executor. Can be external or shared. External Executors include the Gateway. Shared Executors don’t. Defaults to External :type uses_with: Optional[Dict] :param uses_with: dictionary of parameters to overwrite from the default config’s with field :type uses_metas: Optional[Dict] :param uses_metas: dictionary of parameters to overwrite from the default config’s metas field :type uses_requests: Optional[Dict] :param uses_requests: dictionary of parameters to overwrite from the default config’s requests field :param kwargs: other kwargs accepted by the Flow, full list can be found here <https://docs.jina.ai/api/jina.orchestrate.flow.base/>

get_metrics(name=None, documentation=None)[source]

Get a given prometheus metric, if it does not exist yet, it will create it and store it in a buffer. :type name: Optional[str] :param name: the name of the metrics :type documentation: Optional[str] :param documentation: the description of the metrics

Return type

Optional[ForwardRef]

Returns

the given prometheus metrics or None if monitoring is not enable.

class jina.serve.executors.ReducerExecutor(metas=None, requests=None, runtime_args=None, **kwargs)[source]

Bases: jina.serve.executors.BaseExecutor

ReducerExecutor is an Executor that performs a reduce operation on a matrix of DocumentArrays coming from shards. ReducerExecutor relies on DocumentArray.reduce_all to merge all DocumentArray into one DocumentArray which will be sent to the next deployment.

This Executor only adds a reduce endpoint to the BaseExecutor.

metas and requests are always auto-filled with values from YAML config.

Parameters
  • metas (Optional[Dict]) – a dict of metas fields

  • requests (Optional[Dict]) – a dict of endpoint-function mapping

  • runtime_args (Optional[Dict]) – a dict of arguments injected from Runtime during runtime

  • kwargs – additional extra keyword arguments to avoid failing when extra params ara passed that are not expected

reduce(docs_matrix=[], **kwargs)[source]

Reduce docs_matrix into one DocumentArray using DocumentArray.reduce_all :type docs_matrix: List[ForwardRef] :param docs_matrix: a List of DocumentArrays to be reduced :param kwargs: extra keyword arguments :return: the reduced DocumentArray

requests = {'/default': <function ReducerExecutor.reduce>}