def list_events_from_id(stub: NotificationServiceStub, id, timeout_seconds: int = None): request = ListEventsFromIdRequest(id=id, timeout_seconds=timeout_seconds) response = stub.listEventsFromId(request) if response.return_code == str(ReturnStatus.SUCCESS): if response.events is None: return None else: events = [] for event_proto in response.events: event = event_proto_to_event(event_proto) events.append(event) return events else: raise Exception(response.return_msg)
def list_events(stub: NotificationServiceStub, k: str, v: int, timeout_seconds: int = None): request = ListEventsRequest( event=EventProto(key=k, version=v), timeout_seconds=timeout_seconds) response = stub.listEvents(request) if response.return_code == str(ReturnStatus.SUCCESS): if response.events is None: return None else: events = [] for event_proto in response.events: event = event_proto_to_event(event_proto) events.append(event) return events else: raise Exception(response.return_msg)
def send_event(self, event: BaseEvent) -> BaseEvent: """ Send event to Notification :param event: the event updated. :return: A single object of notification created in Notification. """ request = SendEventRequest( event=EventProto(key=event.key, value=event.value, event_type=event.event_type)) response = self.notification_stub.sendEvent(request) if response.return_code == str(ReturnStatus.SUCCESS): if response.event is None: return None else: return event_proto_to_event(response.event) else: raise Exception(response.return_msg)
def list_all_events(self, start_time: int): """ List specific `key` or `version` of events in Notification Service. :param start_time: the event after this time. :return: """ request = ListAllEventsRequest(start_time=start_time) response = self.notification_stub.listAllEvents(request) if response.return_code == str(ReturnStatus.SUCCESS): if response.events is None: return None else: events = [] for event_proto in response.events: event = event_proto_to_event(event_proto) events.append(event) return events else: raise Exception(response.return_msg)
def list_events(self, key: str, version: int = None) -> list: """ List specific `key` or `version` of events in Notification Service. :param key: Key of the event for listening. :param version: (Optional) Version of the signal for listening. :return: Specific `key` or `version` event notification list. """ request = ListEventsRequest(event=EventProto(key=key, version=version)) response = self.notification_stub.listEvents(request) if response.return_code == str(ReturnStatus.SUCCESS): if response.events is None: return None else: events = [] for event_proto in response.events: event = event_proto_to_event(event_proto) events.append(event) return events else: raise Exception(response.return_msg)