class documentation

A Nexus handler manages a collection of Nexus service handlers.

Operation requests are dispatched to a ServiceHandler based on the service name in the operation context.

This class supports user operation handlers that are either async def or def. If def user operation handlers are to be supported, an executor must be provided.

The methods of this class itself are async def. There is currently no alternative Handler class with def methods.

Example

import concurrent.futures
from nexusrpc.handler import Handler

# Create service handler instances
my_service = MyServiceHandler()

# Create handler with async operations only
handler = Handler([my_service])

# Create handler that supports both async and sync operations
executor = concurrent.futures.ThreadPoolExecutor(max_workers=10)
handler = Handler([my_service], executor=executor)

# Use handler to process requests
result = await handler.start_operation(ctx, input_lazy_value)
Method __init__ Initialize a Handler instance from user service handler instances.
Async Method cancel_operation Handle a Cancel Operation request.
Async Method fetch_operation_info Handle a Fetch Operation Info request.
Async Method fetch_operation_result Handle a Fetch Operation Result request.
Async Method start_operation Handle a Start Operation request.
Method _assert_async_callable Undocumented
Method _validate_all_operation_handlers_are_async Undocumented

Inherited from BaseServiceCollectionHandler:

Instance Variable executor Undocumented
Instance Variable service_handlers Undocumented
Method _get_service_handler Return a service handler, given the service name.
Method _register_service_handlers Undocumented
def __init__(self, user_service_handlers: Sequence[Any], executor: concurrent.futures.Executor | None = None):

Initialize a Handler instance from user service handler instances.

The user service handler instances must have been decorated with the @nexusrpc.handler.service_handler decorator.

Parameters
user_service_handlers:Sequence[Any]A sequence of user service handlers.
executor:concurrent.futures.Executor | NoneA concurrent.futures.Executor in which to run non-async def operation handlers.
async def cancel_operation(self, ctx: CancelOperationContext, token: str):

Handle a Cancel Operation request.

Parameters
ctx:CancelOperationContextThe operation context.
token:strThe operation token.
async def fetch_operation_info(self, ctx: FetchOperationInfoContext, token: str) -> OperationInfo:

Handle a Fetch Operation Info request.

Parameters
ctx:FetchOperationInfoContextThe operation context.
token:strThe operation token.
Returns
OperationInfoUndocumented
async def fetch_operation_result(self, ctx: FetchOperationResultContext, token: str) -> Any:

Handle a Fetch Operation Result request.

Parameters
ctx:FetchOperationResultContextThe operation context.
token:strThe operation token.
Returns
AnyUndocumented
async def start_operation(self, ctx: StartOperationContext, input: LazyValueT) -> StartOperationResultSync[Any] | StartOperationResultAsync:

Handle a Start Operation request.

Parameters
ctx:StartOperationContextThe operation context.
input:LazyValueTThe input to the operation, as a LazyValue.
Returns
StartOperationResultSync[Any] | StartOperationResultAsyncUndocumented
def _assert_async_callable(self, method: Callable[..., Any]) -> TypeGuard[Callable[..., Awaitable[Any]]]:

Undocumented

def _validate_all_operation_handlers_are_async(self):

Undocumented