Message¶
- class Message(metadata: Metadata, content: RecordSet | None = None, error: Error | None = None)[source]¶
Bases:
object
State of your application from the viewpoint of the entity using it.
- Parameters:
metadata (Metadata) – A dataclass including information about the message to be executed.
content (Optional[RecordSet]) – Holds records either sent by another entity (e.g. sent by the server-side logic to a client, or vice-versa) or that will be sent to it.
error (Optional[Error]) – A dataclass that captures information about an error that took place when processing another message.
Methods
create_error_reply
(error[, ttl])Construct a reply message indicating an error happened.
create_reply
(content[, ttl])Create a reply to this message with specified content and TTL.
Return True if message has content, else False.
Return True if message has an error, else False.
Attributes
The content of this message.
Error captured by this message.
A dataclass including information about the message to be executed.
- create_error_reply(error: Error, ttl: float | None = None) Message [source]¶
Construct a reply message indicating an error happened.
- Parameters:
error (Error) – The error that was encountered.
ttl (Optional[float] (default: None)) –
Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:
ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)
- Returns:
message – A Message containing only the relevant error and metadata.
- Return type:
- create_reply(content: RecordSet, ttl: float | None = None) Message [source]¶
Create a reply to this message with specified content and TTL.
The method generates a new Message as a reply to this message. It inherits ‘run_id’, ‘src_node_id’, ‘dst_node_id’, and ‘message_type’ from this message and sets ‘reply_to_message’ to the ID of this message.
- Parameters:
content (RecordSet) – The content for the reply message.
ttl (Optional[float] (default: None)) –
Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:
ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)
- Returns:
A new Message instance representing the reply.
- Return type: