nv_ingest_api.util.service_clients.rest package#
Submodules#
nv_ingest_api.util.service_clients.rest.rest_client module#
- class nv_ingest_api.util.service_clients.rest.rest_client.RestClient(
- host: str,
- port: int,
- max_retries: int = 0,
- max_backoff: int = 32,
- default_connect_timeout: float = 300.0,
- default_read_timeout: float | None = None,
- http_allocator: Callable[[], Any] | None = None,
- **kwargs,
Bases:
MessageBrokerClientBase
A client for interfacing with an HTTP endpoint (e.g., nv-ingest), providing mechanisms for sending and receiving messages with retry logic using the requests library by default, but allowing a custom HTTP client allocator.
Extends MessageBrokerClientBase for interface compatibility.
- fetch_message(
- job_id: str,
- timeout: float | Tuple[float, float] | None = None,
Fetches a job result message from the server’s fetch endpoint.
Handles retries for connection errors and non-terminal HTTP errors based on the max_retries configuration. Specific HTTP statuses are treated as immediate failures (terminal) or as job not ready (HTTP 202).
- Parameters:
job_id (str) – The server-assigned identifier of the job to fetch.
timeout (float or tuple of float, optional) – Specific timeout override for this request.
- Returns:
response_code = 0: Success (HTTP 200) with the job result.
response_code = 1: Terminal failure (e.g., 404, 400, 5xx, or max retries exceeded).
response_code = 2: Job not ready (HTTP 202).
- Return type:
- Raises:
TypeError – If the configured client does not support the required HTTP GET method.
- get_client() Any [source]#
Returns the underlying HTTP client instance.
- Returns:
The active HTTP client instance.
- Return type:
Any
- property max_retries: int#
Maximum number of retry attempts configured for operations.
- Returns:
The maximum number of retries.
- Return type:
int
- perform_retry_backoff(existing_retries: int) int [source]#
Performs exponential backoff sleep if retries are permitted.
Calculates the delay using exponential backoff (2^existing_retries) capped by self._max_backoff. Sleeps for the calculated delay if the number of existing_retries is less than max_retries.
- Parameters:
existing_retries (int) – The number of retries already attempted for the current operation.
- Returns:
The incremented retry count (existing_retries + 1).
- Return type:
int
- Raises:
RuntimeError – If existing_retries is greater than or equal to max_retries (when max_retries > 0).
- ping() ResponseSchema [source]#
Checks if the HTTP server endpoint is responsive using an HTTP GET request.
- Returns:
An object encapsulating the outcome: - response_code = 0 indicates success (HTTP status code < 400). - response_code = 1 indicates failure, with details in response_reason.
- Return type:
- submit_message(
- channel_name: str,
- message: str,
- for_nv_ingest: bool = False,
- timeout: float | Tuple[float, float] | None = None,
Submits a job message payload to the server’s submit endpoint.
Handles retries for connection errors and non-terminal HTTP errors based on the max_retries configuration. Specific HTTP statuses are treated as immediate failures.
- Parameters:
channel_name (str) – Not used by RestClient; included for interface compatibility.
message (str) – The JSON string representing the job specification payload.
for_nv_ingest (bool, optional) – Not used by RestClient. Default is False.
timeout (float or tuple of float, optional) – Specific timeout override for this request.
- Returns:
response_code = 0: Success (HTTP 200) with a successful job submission.
response_code = 1: Terminal failure (e.g., 422, 400, 5xx, or max retries exceeded).
- Return type:
- Raises:
TypeError – If the configured client does not support the required HTTP POST method.