nuropb.contexts.service_handlers

This module provides features that handle the execution of nuropb service messages: Requests, Commands and Events.

Attempt is made to make the code agnostic to the underlying transport.

ROADMAP Features and Considerations (in no particular order):

  • method parameter validation

  • post ack commit or rollback configured by the implementation

Module Contents

Functions

verbose

error_dict_from_exception

Creates an error dict from an exception

create_transport_response_from_rmq_decode_exception

Creates a NuroPb response from an unsupported message received over RabbitMQ

create_transport_responses_from_exceptions

Creates a NuroPb response from an exceptions and also accommodates special cases like NuropbCallAgain and NuropbSuccess

handle_execution_result

This function is called from the execute_request() to handle both synchronous and asynchronous results

execute_request

Executes a transport request and call the message_complete_callback with the result

Data

logger

_verbose

API

nuropb.contexts.service_handlers.logger

None

nuropb.contexts.service_handlers._verbose

False

nuropb.contexts.service_handlers.verbose() bool
nuropb.contexts.service_handlers.error_dict_from_exception(exception: Exception | BaseException) Dict[str, str]

Creates an error dict from an exception

Parameters:

exception

Returns:

nuropb.contexts.service_handlers.create_transport_response_from_rmq_decode_exception(exception: Exception | BaseException, basic_deliver: pika.spec.Basic.Deliver, properties: pika.spec.BasicProperties) Tuple[nuropb.interface.AcknowledgeAction, list[nuropb.interface.TransportRespondPayload]]

Creates a NuroPb response from an unsupported message received over RabbitMQ

nuropb.contexts.service_handlers.create_transport_responses_from_exceptions(service_message: nuropb.interface.TransportServicePayload, exception: Exception | BaseException) Tuple[nuropb.interface.AcknowledgeAction, list[nuropb.interface.TransportRespondPayload]]

Creates a NuroPb response from an exceptions and also accommodates special cases like NuropbCallAgain and NuropbSuccess

Parameters:
  • service_message

  • exception

Returns:

nuropb.contexts.service_handlers.handle_execution_result(service_message: nuropb.interface.TransportServicePayload, result: Any, message_complete_callback: nuropb.interface.MessageCompleteFunction) None

This function is called from the execute_request() to handle both synchronous and asynchronous results

With standard implementation message_complete_callback is defined in the transport layer.

  • For service messages transport.on_service_message_complete() is used

  • For response messages transport.on_response_message_complete() is used.

#FUTURE: There is consideration of how to pass a context through this flow to until the transport acknowledgement has completed. This is to allow for the possibility of a post ack commit or rollback. It also allows to more flexible handling for events raised during requests, commands and incoming events

Parameters:
  • service_message

  • result

  • message_complete_callback

Returns:

nuropb.contexts.service_handlers.execute_request(service_instance: object, service_message: nuropb.interface.TransportServicePayload, message_complete_callback: nuropb.interface.MessageCompleteFunction) None

Executes a transport request and call the message_complete_callback with the result

PLEASE NOTE: At first glance awaitable nature of the result_future is not obvious from the code. read the comments in transformed_async_future() to understand how the result_future is handled before making any changes.

Parameters:
  • service_instance – object

  • service_message – TransportServicePayload

  • message_complete_callback – MessageCompleteFunction

Returns:

None