def send_event_later(self, event: EventEnvelope, seconds: float = 1.0, me=True): if event.get_reply_to() is not None: event.set_reply_to(event.get_reply_to(), me) self.platform.send_event_later(event, seconds)
def send_event(self, event: EventEnvelope, broadcast=False) -> None: if not isinstance(event, EventEnvelope): raise ValueError("event object must be an EventEnvelope class") # restore distributed tracing info from current thread trace_info = self.get_trace() if trace_info: event.set_trace(trace_info.get_id(), trace_info.get_path()) # regulate rate for best performance self._seq += 1 self._throttle.regulate_rate(self._seq) route = event.get_to() if broadcast: event.set_broadcast(True) reply_to = event.get_reply_to() if reply_to: target = reply_to[2:] if reply_to.startswith('->') else reply_to if route == target: raise ValueError("route and reply_to must not be the same") if route in self._function_queues: if event.is_broadcast() and self._cloud.is_connected(): self._cloud.send_payload({ 'type': 'event', 'event': event.to_map() }) else: self._loop.call_soon_threadsafe(self._send, route, event.to_map()) else: if self._cloud.is_connected(): self._cloud.send_payload({ 'type': 'event', 'event': event.to_map() }) else: raise ValueError("route " + route + " not found")
def send_event(self, event: EventEnvelope, me=True): if event.get_reply_to() is not None: event.set_reply_to(event.get_reply_to(), me) self.platform.send_event(event)