Hook Module
mosaicolabs.hook.HookServer ¶
Receives the events mosaicod sends to a hook, and passes each one to every receiver.
Register the server's URL with mosaicod hook create <URL>.
Requests aren't authenticated, so anything that can reach the server can send it events. Keep it on a network only mosaicod can reach.
Example
start ¶
Listens for events until interrupted, for example with Ctrl-C.
host and port are where this server listens. Register
that URL with mosaicod hook create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The address to listen on. The default, |
'127.0.0.1'
|
port
|
int
|
The port to listen on. Keep it fixed, so the URL registered in mosaicod stays valid across restarts. |
DEFAULT_PORT
|
log_level
|
str | None
|
If set, for example to |
None
|
It logs where it listens, and any receiver that raises. Unless log_level is
set or logging is already set up, for example with setup_sdk_logging or
logging.basicConfig, it first calls setup_sdk_logging(), which logs INFO
and above to stderr.
mosaicolabs.hook.Event ¶
Bases: BaseModel
Base class of the events mosaicod sends to hooks.
A receiver gets every event, and tells them apart by their class:
Example
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Identifies the event. A retry delivers the same event with the same id. |
mosaicolabs.hook.TopicUploaded ¶
Bases: Event
A topic's upload finished, and its data can't change anymore.
Attributes:
| Name | Type | Description |
|---|---|---|
sequence_name |
str
|
The topic's sequence. |
topic_name |
str
|
The topic. |
session_locator |
str
|
The session the topic was uploaded in, as
|
ontology_tag |
str
|
The ontology tag of the topic's data. |
user_metadata |
dict[str, Any] | None
|
The metadata given when the topic was created, if any. |
created_timestamp |
int
|
When the topic was created, in Unix nanoseconds. |
mosaicolabs.hook.SessionUploaded ¶
Bases: Event
A session was finalized, and all its topics are uploaded.
Attributes:
| Name | Type | Description |
|---|---|---|
sequence_name |
str
|
The session's sequence. |
session_locator |
str
|
The session, as |
topics |
list[str]
|
The names of the session's topics. |
created_timestamp |
int
|
When the session was created, in Unix nanoseconds. |