Messages#
A message is a data container used to exchange data across nodes.
property |
type |
description |
---|---|---|
|
|
name or id of the creating node |
|
|
message data version |
|
|
data to be transferred upstream in the pipeline |
|
|
message metadata |
|
|
collection of timers to evaluate performed data operations |
An empty message is created with:
creator
set toNone
version
set to-1
payload
set toNone
method |
arguments |
description |
---|---|---|
|
|
create a message by copying another message |
|
|
convert the message to dict |
|
|
convert the message to json string, with a provided encoder |
|
|
add timer to message |
Notes:
currently,
to_json()
simply returns thejson.dumps()
on the dictionary version of a message; this means that generating a json string for the message will fail if the message payload is not serialisable using the encoder function provided as argument
Timers#
In order to keep track of any operations performed to generate the data
contained in a message, a context manager, timeit
, is offered to
automatically create within the message timers
dictionary a relevant entry.
>>> m = Message()
>>> with m.timeit('timer_name'):
>>> time.sleep(1)
>>> m.timers
{'timer_name': 1.001392364501953}
Alternatively, set a timer using the timer()
method:
>>> m = Message()
>>> m.timer('timer_name', 1.1)
>>> m.timers
{'timer_name': 1.1}