class documentation

class OperationHandler(ABC, Generic[InputT, OutputT]):

Known subclasses: nexusrpc.handler._operation_handler.SyncOperationHandler

View In Hierarchy

Base class for an operation handler in a Nexus service implementation.

To define a Nexus operation handler, create a method on your service handler class that takes self and returns an instance of OperationHandler, and apply the @nexusrpc.handler.operation_handler decorator.

To create an operation handler that is limited to returning synchronously, use @nexusrpc.handler.SyncOperationHandler to create the instance of OperationHandler from the start method.

Method cancel Cancel the operation.
Method fetch_info Return information about the current status of the operation.
Method fetch_result Return the result of the operation.
Method start Start the operation, completing either synchronously or asynchronously.
@abstractmethod
def cancel(self, ctx: CancelOperationContext, token: str) -> None | Awaitable[None]:

Cancel the operation.

@abstractmethod
def fetch_info(self, ctx: FetchOperationInfoContext, token: str) -> OperationInfo | Awaitable[OperationInfo]:

Return information about the current status of the operation.

@abstractmethod
def fetch_result(self, ctx: FetchOperationResultContext, token: str) -> OutputT | Awaitable[OutputT]:

Return the result of the operation.

@abstractmethod
def start(self, ctx: StartOperationContext, input: InputT) -> StartOperationResultSync[OutputT] | Awaitable[StartOperationResultSync[OutputT]] | StartOperationResultAsync | Awaitable[StartOperationResultAsync]:

Start the operation, completing either synchronously or asynchronously.

Returns the result synchronously, or returns an operation token. Which path is taken may be decided at operation handling time.