jina.serve.runtimes.worker.request_handling module#
- class jina.serve.runtimes.worker.request_handling.WorkerRequestHandler(args, logger, metrics_registry=None, tracer_provider=None, meter_provider=None, deployment_name='', **kwargs)[source]#
Bases:
object
Object to encapsulate the code related to handle the data requests passing to executor and its returned values
Initialize private parameters and execute private loading functions.
- Parameters:
args (
Namespace
) – args from CLIlogger (
JinaLogger
) – the logger provided by the usermetrics_registry (
Optional
[CollectorRegistry
]) – optional metrics registry for prometheus used if we need to expose metrics from the executor of from the data request handlertracer_provider (
Optional
[TracerProvider
]) – Optional tracer_provider that will be provided to the executor for tracingmeter_provider (
Optional
[MeterProvider
]) – Optional meter_provider that will be provided to the executor for metricsdeployment_name (
str
) – name of the deployment to use as Executor name to set in requestskwargs – extra keyword arguments
- async handle(requests, tracing_context=None)[source]#
Initialize private parameters and execute private loading functions.
- Parameters:
requests (
List
[DataRequest
]) – The messages to handle containing a DataRequesttracing_context (
Optional
[Context
]) – Optional OpenTelemetry tracing context from the originating request.
- Return type:
- Returns:
the processed message
- static replace_docs(request, docs, ndarrray_type=None)[source]#
Replaces the docs in a message with new Documents.
- Parameters:
request (
List
[DataRequest
]) – The request objectdocs (
DocumentArray
) – the new docs to be usedndarrray_type (
Optional
[str
]) – type tensor and embedding will be converted to
- Return type:
None
- static replace_parameters(request, parameters)[source]#
Replaces the parameters in a message with new Documents.
- Parameters:
request (
List
[DataRequest
]) – The request objectparameters (
Dict
) – the new parameters to be used
- Return type:
None
- static merge_routes(requests)[source]#
Merges all routes found in requests into the first message
- Parameters:
requests (
List
[DataRequest
]) – The messages containing the requests with the routes to merge- Return type:
None
- async close()[source]#
Close the data request handler, by closing the executor and the batch queues.
- static get_parameters_dict_from_request(requests)[source]#
Returns a parameters dict from a list of DataRequest objects. :type requests:
List
[DataRequest
] :param requests: List of DataRequest objects :rtype:Dict
:return: parameters matrix: list of parameters (Dict) objects
- static get_docs_from_request(requests)[source]#
Gets a field from the message
- Parameters:
requests (
List
[DataRequest
]) – requests to get the docs from- Return type:
- Returns:
DocumentArray extracted from the field from all messages
- static reduce(docs_matrix)[source]#
Reduces a list of DocumentArrays into one DocumentArray. Changes are applied to the first DocumentArray in-place.
Reduction consists in reducing every DocumentArray in docs_matrix sequentially using
DocumentArray
.:method:reduce. The resulting DocumentArray contains Documents of all DocumentArrays. If a Document exists in many DocumentArrays, data properties are merged with priority to the left-most DocumentArrays (that is, if a data attribute is set in a Document belonging to many DocumentArrays, the attribute value of the left-most DocumentArray is kept). Matches and chunks of a Document belonging to many DocumentArrays are also reduced in the same way. Other non-data properties are ignored.Note
- Matches are not kept in a sorted order when they are reduced. You might want to re-sort them in a later
step.
The final result depends on the order of DocumentArrays when applying reduction.
- Parameters:
docs_matrix (
List
[DocumentArray
]) – List of DocumentArrays to be reduced- Return type:
Optional
[DocumentArray
]- Returns:
the resulting DocumentArray
- static reduce_requests(requests)[source]#
Reduces a list of requests containing DocumentArrays into one request object. Changes are applied to the first request object in-place.
Reduction consists in reducing every DocumentArray in requests sequentially using
DocumentArray
.:method:reduce. The resulting DataRequest object contains Documents of all DocumentArrays inside requests.- Parameters:
requests (
List
[DataRequest
]) – List of DataRequest objects- Return type:
- Returns:
the resulting DataRequest