"""
The ska_oso_scripting.api.functional.messages module contains functions that scripts can use
to announce events and messages to the outside world.
"""
import threading
from pubsub import pub
from ska_oso_scripting.topics import user_topics
__all__ = [
"publish_event_message",
"send_message",
]
[docs]
def send_message(topic, **kwargs):
"""
Helper function to send messages via pypubsub.
:param topic: topic matching a topic in ska_oso_scripting.topics
:param kwargs: kwargs to be included in message
"""
pub.sendMessage(topic, msg_src=threading.current_thread().name, **kwargs)
[docs]
def publish_event_message(topic=user_topics.script.announce, **kwargs):
"""
publish pypubsub event messages, OET scripts will be using this method
to publish a freeform messages to an unknown listener.
:param topic: message topic
:param kwargs: any metadata associated with pypubsub message
"""
# TODO:the custom topic should be a unique one, compare it with ska_oso_scripting.topics
send_message(topic, **kwargs)