def __init__( self, flux_handle, topic, payload=None, nodeid=flux.constants.FLUX_NODEID_ANY, flags=0, ): # hold a reference for destructor ordering self._handle = flux_handle dest = raw.flux_future_destroy super(RPC.InnerWrapper, self).__init__( ffi, lib, handle=None, match=ffi.typeof(lib.flux_rpc).result, prefixes=["flux_rpc_"], destructor=dest, ) if isinstance(flux_handle, Wrapper): flux_handle = flux_handle.handle topic = encode_topic(topic) payload = encode_payload(payload) self.handle = raw.flux_rpc(flux_handle, topic, payload, nodeid, flags)
def __init__(self, flux_handle, topic, payload=None, rankset="all", flags=0): # hold a reference for destructor ordering self._handle = flux_handle dest = raw.flux_mrpc_destroy super(MRPC.InnerWrapper, self).__init__( ffi, lib, handle=None, match=ffi.typeof(lib.flux_mrpc).result, prefixes=["flux_mrpc_"], destructor=dest, ) # pylint: disable=duplicate-code if isinstance(flux_handle, Wrapper): flux_handle = flux_handle.handle topic = encode_topic(topic) payload = encode_payload(payload) rankset = encode_rankset(rankset) self.handle = raw.flux_mrpc(flux_handle, topic, payload, rankset, flags)
def respond(self, message, payload=None): """Respond to a flux rpc :param message: The message to respond to :type message: Message :param payload: The (optional) payload to include in the response :type payload: None, str, bytes, unicode, or json-serializable """ if isinstance(message, Message): message = message.handle payload = encode_payload(payload) return self.flux_respond(message, payload)
def __init__( self, flux_handle, topic, payload=None, nodeid=flux.constants.FLUX_NODEID_ANY, flags=0, ): if isinstance(flux_handle, Wrapper): # keep the flux_handle alive for the lifetime of the RPC self.flux_handle = flux_handle flux_handle = flux_handle.handle topic = encode_topic(topic) payload = encode_payload(payload) future_handle = raw.flux_rpc(flux_handle, topic, payload, nodeid, flags) super(RPC, self).__init__(future_handle, prefixes=["flux_rpc_", "flux_future_"])
def payload(self, value): self.payload_str = encode_payload(value)
def from_event_encode(cls, topic, payload=None): payload = encode_payload(payload) handle = raw.flux_event_encode(topic, payload) return cls(handle=handle)