def _event_handler(self, event): """Internal event handler""" if not event.error: if event.name == Events.GARDEN_REMOVED.name: self.remove_garden_from_list(garden_name=event.payload.name) elif event.name == Events.GARDEN_UPDATED.name: skip_key = None if event.payload.connection_type: if event.payload.connection_type.casefold() == "stomp": stomp_config = event.payload.connection_params.get( "stomp", {}) stomp_config = deepcopy(stomp_config) stomp_config["send_destination"] = None skip_key = self.add_connection( stomp_config=stomp_config, name=event.payload.name) self.remove_garden_from_list(garden_name=event.payload.name, skip_key=skip_key) if not event_blocklisted(event): for value in self.conn_dict.values(): conn = value["conn"] if conn: if conn.is_connected(): if value["headers_list"]: for headers in value["headers_list"]: conn.send(event, headers=headers) else: conn.send(event)
def process(self, event: Event): # TODO - This shouldn't be set here event.garden = conf.get("garden.name") if not event_blocklisted(event): try: operation = Operation( operation_type="PUBLISH_EVENT", model=event, model_type="Event" ) self._ez_client.forward(operation) except RequestException as ex: self.logger.error(f"Error while publishing event to parent: {ex}") self._connected = False self._reconnect()
def test_can_send_event_to_parent_blocklist(self, command_blocklist, monkeypatch): monkeypatch.setattr(config, "get", self.config_get) assert event_blocklisted(self.event)
def test_can_send_event_error(self, monkeypatch): monkeypatch.setattr(config, "get", self.config_get) event = Event(name="REQUEST_CREATE", error=True) assert event_blocklisted(event)
def test_event_not_request(self, monkeypatch): monkeypatch.setattr(config, "get", self.config_get) event = Event(name="ENTRY_STARTED") assert not event_blocklisted(event)
def test_command_missing_in_blocklist(self, monkeypatch): monkeypatch.setattr(config, "get", self.config_get) assert not event_blocklisted(self.event)
def test_command_exists_in_blocklist(self, command_blocklist, monkeypatch): monkeypatch.setattr(config, "get", self.config_get) assert event_blocklisted(self.event)