ocd.heart_beat – Control the OCD main loop status and wait for connections

Heartbeat functionality

ocd.heart_beat.ENQUIRY_TOPIC = 'ocd.heartbeat.enquiry'

Topic sent when enquiring about heartbeat status

ocd.heart_beat.REPLY_TOPIC = 'ocd.heartbeat.reply'

Topic expected as a reply when enquiring about heartbeat status

class ocd.heart_beat.HeartBeatQuery(*args, **kwargs)[source]

Bases: ocd.utils.SendAndListen

Specialized version of SendAndListen to monitor if the OCD heart beats.

Can also be used to check that a OCD subcommand is in contact with the OCD main loop (ocd run).

Parameters:
all : same as SendAndListen
Attributes:
id_ : str

unique token associated with the current HeartBeatQuery instance. It is send as part of the event sent ({'id': id_}) and it is expected in the answer.

classmethod from_addresses(server_address, listener_addresses, **kwargs)[source]

Same as ocd.utils.SendAndListen.from_addresses(), but with the topic set to REPLY_TOPIC.

classmethod from_names(server_name, listener_name, **kwargs)[source]

Same as ocd.utils.SendAndListen.from_names(), but with the topic set to REPLY_TOPIC.

communicate(self)[source]

Send a ENQUIRY_TOPIC with the id_ in the event and expects a REPLY_TOPIC with the same id.

Returns:
same as ocd.utils.SendAndListen.communicate()
class ocd.heart_beat.HeartBeatHandler(server)[source]

Bases: object

The handle_event() handles events coming from HeartBeatQuery and send out a reply.

Parameters:
server : tcs_lib.server.ZMQServer

server to use to send out events

Attributes:
topics : list

topics handled by the state machine (ENQUIRY_TOPIC)

classmethod from_address(server_address)[source]

Initialize the class from the server address

Parameters:
server_address : string

url/path/… use to initialize the server

classmethod from_name(server_name)[source]

Initialize the class from the server name. Uses ocd.utils.get_zmq_server().

Parameters:
server_name : string

name of the server as saved by ocd.utils.init_zmq_servers()

handle_event(self, tcs_topic, tcs_event)[source]

Handle a TCS event with topics and re-emit the input event with topic REPLY_TOPIC on the server passed to the constructor.

Parameters:
tcs_topic : string

topic of the event

tcs_event : dict

event to handle

Returns:
bool

True if the event has been correctly handled, False otherwise