hbp_nrp_simserver.server.mqtt_notifier module¶
This module implements a MQTT Notifier interface for status/error messages.
-
class
hbp_nrp_simserver.server.mqtt_notifier.
MQTTNotifier
(sim_id: int, broker_hostname: str = 'localhost', broker_port: int = 1883, topics_prefix: str = '', client_id: Optional[str] = 'mqtt_notifier')[source]¶ Bases:
object
This class encapsulates publishing of state/errors/task status to the frontend/clients.
-
DEFAULT_MQTT_CLIENT_ID
= 'mqtt_notifier'¶
-
publish_error
(error_msg)[source]¶ Publishes an error message
- Parameters
error_msg – A string of formatted JSON to publish.
-
publish_status
(msg)[source]¶ Publishes a state message
- Parameters
msg – A string of formatted JSON to publish.
-
start_task
(task_name, subtask_name, number_of_subtasks, block_ui=False)[source]¶ Sends, on the MQTT status topic, a notification that a task is starting. This method will save the task name and the task size in class members so that it could be reused in subsequent call to the update_task method.
- Parameters
task_name – Title of the task (example: initializing experiment).
subtask_name – Title of the first subtask. Could be empty (example: ‘loading…’).
number_of_subtasks – Number of expected subsequent calls to update_current_task(_, True, _).
block_ui – Indicate that the client should block any user interaction.
-
task_notifier
(task_name, subtask_name=None)[source]¶ Task notifier context manager
- Parameters
task_name –
subtask_name –
-
update_task
(new_subtask_name, update_progress, block_ui=False)[source]¶ Sends a status notification that the current task is updated with a new subtask.
- Parameters
subtask_name – Title of the first subtask. Could be empty (example: ‘Loading Foo…’).
update_progress – Boolean indicating if the index of the current subtask should be updated (usually yes).
block_ui – Indicate that the client should block any user interaction.
-