Quantum Resource Manager and Compiler Infrastructure (QRM&CI) 0.1.0
DaemonMessaging.h File Reference
Include dependency graph for DaemonMessaging.h:

Functions

template<class Message, class Handler>
bool mqss::qrmci::receiveNext (CommunicationHandler &comms, const std::string &queueName, std::chrono::milliseconds timeout, const std::atomic< bool > &terminationFlag, Handler &&handle)
 Receive one message from a queue and hand it to handle.
template<class Message, class Handler>
bool mqss::qrmci::drainQueue (CommunicationHandler &comms, const std::string &queueName, const std::atomic< bool > &terminationFlag, Handler &&handle)
 Receive from a queue until it is empty or the broker fails, handing every message to handle.
template<class Message>
void mqss::qrmci::send (CommunicationHandler &comms, const Message &message, const std::string &queueName)
 Send a message, logging rather than propagating a failure.
void mqss::qrmci::sendFailure (CommunicationHandler &comms, const mqss::QuantumTask &task, const Error &failure, std::string_view stage)
 Tell a task's submitter that the task failed, and log why.
void mqss::qrmci::sendResult (CommunicationHandler &comms, const mqss::QuantumTask &task, const mqss::QuantumResult &result)
 Send a task's result to its own result destination, and log it.

Detailed Description

The queue I/O every QRM&CI daemon work loop shares: receiving and draining a queue, and the best-effort sends a work loop makes, including telling a task's submitter how it ended.

Definition in file DaemonMessaging.h.

Function Documentation

◆ drainQueue()

template<class Message, class Handler>
bool mqss::qrmci::drainQueue ( CommunicationHandler & comms,
const std::string & queueName,
const std::atomic< bool > & terminationFlag,
Handler && handle )

Receive from a queue until it is empty or the broker fails, handing every message to handle.

Template Parameters
MessageThe message type to receive.
HandlerCallable as handle(Message &&), invoked once per message.
Parameters
commsThe handler to receive through.
queueNameThe queue to drain.
terminationFlagConsulted before each poll; see receiveNext()'s own documentation.
handleInvoked with each received message.
Returns
True if at least one message was handled.

Definition at line 73 of file DaemonMessaging.h.

◆ receiveNext()

template<class Message, class Handler>
bool mqss::qrmci::receiveNext ( CommunicationHandler & comms,
const std::string & queueName,
std::chrono::milliseconds timeout,
const std::atomic< bool > & terminationFlag,
Handler && handle )

Receive one message from a queue and hand it to handle.

Neither an empty queue nor a broker failure is fatal to a work loop: both simply mean there is nothing to do this turn, the second after a warning.

Template Parameters
MessageThe message type to receive.
HandlerCallable as handle(Message &&).
Parameters
commsThe handler to receive through.
queueNameThe queue to consume from.
timeoutHow long to wait; 0ms polls once and returns immediately.
terminationFlagConsulted before the receive attempt (and between polls of an indefinite wait), so a shutdown interrupts the wait rather than outliving it. The caller supplies this explicitly – a daemon passes its own process-wide flag; a test or short-lived tool that never shuts down can pass one that is never set.
handleInvoked with the received message, if one arrived.
Returns
True if a message was received and handed to handle.

Definition at line 46 of file DaemonMessaging.h.

◆ send()

template<class Message>
void mqss::qrmci::send ( CommunicationHandler & comms,
const Message & message,
const std::string & queueName )

Send a message, logging rather than propagating a failure.

Every send a running daemon makes is best-effort: a broker that rejects a message must not cost the daemon its in-flight work, so a failure is logged and the loop carries on.

Template Parameters
MessageThe message type to send.
Parameters
commsThe handler to send through.
messageThe message to send.
queueNameThe queue to send it to.

Definition at line 96 of file DaemonMessaging.h.

◆ sendFailure()

void mqss::qrmci::sendFailure ( CommunicationHandler & comms,
const mqss::QuantumTask & task,
const Error & failure,
std::string_view stage )
inline

Tell a task's submitter that the task failed, and log why.

Parameters
commsThe handler to send through.
taskThe task that failed.
failureThe failure to report, carried into the cancellation message the submitter receives.
stageWhat the daemon was doing, e.g. could not be scheduled.

Definition at line 109 of file DaemonMessaging.h.

◆ sendResult()

void mqss::qrmci::sendResult ( CommunicationHandler & comms,
const mqss::QuantumTask & task,
const mqss::QuantumResult & result )
inline

Send a task's result to its own result destination, and log it.

Parameters
commsThe handler to send through.
taskThe task the result belongs to.
resultThe result to send.

Definition at line 122 of file DaemonMessaging.h.