orangeqs.juice.client#
OrangeQS Juice Client API.
Submodules#
Package Contents#
Classes#
Client for OrangeQS Juice. |
API#
- class orangeqs.juice.client.Client#
Client for OrangeQS Juice.
This class provides methods to interact with components of OrangeQS Juice, like OrangeQS Juice services, messaging, tasks and the database.
Examples#
Instantiating a client.
from orangeqs import juice client = juice.Client()
- async request(service: str, task: orangeqs.juice.task.Task, *, check: bool = False) orangeqs.juice.task.TaskFuture[orangeqs.juice.task.TaskResultOk] | orangeqs.juice.task.TaskFuture[orangeqs.juice.task.TaskResult]#
Request a task to be executed and return a future for the result.
After this function returns the request was sent to the task manager, but the task may not have been executed yet. Use the returned future to await the task result.
Parameters#
service (str): The name of the service to execute the task on.
task (Task): The task to execute.
check (bool, optional): Whether to check for errors in the task result. If true, raises a
TaskExecutionErrorif the task resulted in an error.
Returns#
(TaskFuture): A future that will resolve to the task result. The type of the result depends on the
checkparameter. Ifcheckis True, the future will resolve to aTaskResultOk. Ifcheckis False, the future will resolve to aTaskResult(eitherTaskResultOkorTaskResultError).
Raises#
(TaskExecutionError): If
checkis True and the task resulted in an error. This error is not raised by this function, but by the returned future.
Examples#
Using the default, which is equivalent to
check=False:request = await client.request("my-service", MyTask()) result = await request if isinstance(result, TaskResultError): # Handle error ... else: # Handle success ...
Using
check=True:request = await client.request("my-service", MyTask(), check=True) try: result = await request # Handle success ... except TaskExecutionError as error: # Handle error ...
- async execute(service: str, task: orangeqs.juice.task.Task, *, check: bool = False) orangeqs.juice.task.TaskResult#
Execute a task, wait for the result, returning a
TaskResult.This is equivalent to calling
await (await client.request(...)). Seerequest()for examples.Parameters#
service (str): The name of the service to execute the task on.
task (Task): The task to execute.
check (bool, optional): Whether to check for errors in the task result. If true, raises a
TaskExecutionErrorif the task resulted in an error.
Returns#
(TaskResult): The result of the task execution. If
checkis True, this will be aTaskResultOk. Ifcheckis False, this will be aTaskResult(either aTaskResultOkor aTaskResultError)
Raises#
(TaskExecutionError): If
checkis True and the task resulted in an error.
- execute_blocking(service: str, task: orangeqs.juice.task.Task, *, check: bool = False, timeout: float | None = None) orangeqs.juice.task.TaskResult#
Execute a task, wait for the result, returning a
TaskResult.This is the synchronous (blocking) version of
execute(). Seerequest()for examples.Parameters#
service (str): The name of the service to execute the task on.
task (Task): The task to execute.
check (bool, optional): Whether to check for errors in the task result. If true, raises a
TaskExecutionErrorif the task resulted in an error.timeout (float, optional): The maximum time to wait for the task result, in seconds. If None, waits indefinitely. This includes connecting to the task manager, sending the request, executing the task and waiting for the result. Note that if the timeout is exceeded the task is not cancelled, it will continue executing on the service!
Returns#
(TaskResult): The result of the task execution. If
checkis True, this will be aTaskResultOk. Ifcheckis False, this will be aTaskResult(either aTaskResultOkor aTaskResultError)
Raises#
(TaskExecutionError): If
checkis True and the task resulted in an error.(TimeoutError): If a
timeoutwas specified and the task result was not received within the given time.