orangeqs.juice.client._task#
Sending tasks to a service over a websocket connection.
Module Contents#
Classes#
Client to send tasks to be executed over a websocket connection. |
|
Mixin providing a registry of task clients. |
Data#
API#
- class orangeqs.juice.client._task.TaskClient(base_url: str, websocket_kwargs: dict[str, Any] | None = None)#
Client to send tasks to be executed over a websocket connection.
- base_connection_delay: float#
None
Base delay in seconds for exponential backoff between connection attempts.
- async connect() None#
Wait until connected to the server.
Will start the connect and receive loop if it has not been started yet.
Raises#
(RuntimeError): If the client has been closed and cannot be reused.
(ConnectionError): If the connection could not be established.
- close() None#
Close the connection to the server.
This stops the receive loop and prevents further requests.
- async request_raw(task_id: str, message: str | bytes) orangeqs.juice.task.TaskFuture[dict[str, Any]]#
Request a task to be executed from raw data.
As this function returns, it means the request has been sent to the server, but the task may not have been executed yet. Use the returned future to wait for the task result.
Parameters#
task_id (str): The ID of the task to send.
message (str | bytes): The raw message representing the task to send.
Returns#
(TaskFuture): A future that will resolve to the task result.
- async request(target: str, task: orangeqs.juice.task.Task) orangeqs.juice.task.TaskFuture[dict[str, Any]]#
Request a task to be executed.
As this function returns, it means the request has been sent to the server, but the task may not have been executed yet. Use the returned future to wait for the task result.
Parameters#
target (str): The target service to execute the task on.
task (Task): The task to execute.
Returns#
(TaskFuture): A future that will resolve to the task result.
- async execute(target: str, task: orangeqs.juice.task.Task) dict[str, Any]#
Execute a task and wait for the result.
This is equivalent to calling
await (await client.request(...)).Parameters#
target (str): The target service to execute the task on.
task (Task): The task to execute.
Returns#
(dict): The result of the task.
- class orangeqs.juice.client._task.TaskClientBlocking(base_url: str, websocket_kwargs: dict[str, Any] | None = None)#
-
- base_connection_delay: float#
None
Base delay in seconds for exponential backoff between connection attempts.
- connect() None#
Wait until connected to the server.
Attempts to connect multiple times with exponential backoff. Tries for
max_connection_attemptstimes before giving up.Raises#
(RuntimeError): If the client has been closed and cannot be reused.
(ConnectionError): If the connection could not be established.
- close() None#
Close the connection to the server.
This prevents further requests. This can be called multiple times.
- execute(target: str, task: orangeqs.juice.task.Task, timeout: float | None = None) Any#
Execute a task and wait for the result.
This is equivalent to calling
await (await client.request(...)).Parameters#
target (str): The target service to execute the task on.
task (Task): The task to execute.
timeout (float | None): Optional timeout for sending the task and receiving the result.
Returns#
(dict): The result of the task.
- orangeqs.juice.client._task.TaskClientClass#
‘TypeVar(…)’
- class orangeqs.juice.client._task.TaskClientProvider(task_server_config: orangeqs.juice.schemas.tasks.TaskServerConfigs, task_manager_config: orangeqs.juice.schemas.task_manager.TaskManagerConfig, client_class: type[orangeqs.juice.client._task.TaskClientClass])#
Bases:
typing.Generic[orangeqs.juice.client._task.TaskClientClass]Mixin providing a registry of task clients.
- client_factory(target: str) orangeqs.juice.client._task.TaskClientClass#
Create a new TaskClient for the given target.
- client_for_target(target: str) orangeqs.juice.client._task.TaskClientClass#
Get a cached client or create a new one for the given target.
Automatically cleans up closed clients.
- orangeqs.juice.client._task.task_result_adapter#
‘(…)’