Ejemplo n.º 1
0
 def list_events(self,
                 key: Union[str, Tuple[str]],
                 version: int = None,
                 event_type: str = None,
                 start_time: int = None,
                 namespace: str = None):
     key = None if key == "" else key
     version = None if version == 0 else version
     event_type = None if event_type == "" else event_type
     namespace = None if namespace == "" else namespace
     if isinstance(key, str):
         key = (key,)
     elif isinstance(key, Iterable):
         key = tuple(key)
     res = MongoEvent.get_base_events(self.server_id, key, version, event_type, namespace)
     return res
Ejemplo n.º 2
0
 def add_event(self, event: BaseEvent):
     kwargs = {
         "server_id": self.server_id,
         "create_time": time.time_ns(),
         "event_type": event.event_type,
         "key": event.key,
         "value": event.value,
     }
     mongo_event = MongoEvent(**kwargs)
     mongo_event.save()
     mongo_event.reload()
     event.create_time = mongo_event.create_time
     event.version = mongo_event.version
     event.id = mongo_event.auto_increase_id
     return event
Ejemplo n.º 3
0
 def add_event(self, event: BaseEvent, uuid: str):
     kwargs = {
         "server_id": self.server_id,
         "create_time": int(time.time() * 1000),
         "event_type": event.event_type,
         "key": event.key,
         "value": event.value,
         "context": event.context,
         "namespace": event.namespace,
         "uuid": uuid
     }
     mongo_event = MongoEvent(**kwargs)
     mongo_event.save()
     mongo_event.reload()
     event.create_time = mongo_event.create_time
     event.version = mongo_event.version
     return event
Ejemplo n.º 4
0
 def clean_up(self):
     MongoEvent.delete_by_client(self.server_id)
Ejemplo n.º 5
0
 def list_all_events_from_id(self, id: int):
     res = MongoEvent.get_base_events_by_id(self.server_id, id)
     return res
Ejemplo n.º 6
0
 def list_all_events(self, start_time: int):
     res = MongoEvent.get_base_events_by_time(self.server_id, start_time)
     return res
Ejemplo n.º 7
0
 def list_events(self, key: str, version: int = None):
     res = MongoEvent.get_base_events_by_version(self.server_id, key,
                                                 version)
     return res
Ejemplo n.º 8
0
 def get_latest_version(self, key: str = None):
     mongo_events = MongoEvent.get_by_key(self.server_id, key, 0, 1,
                                          "-version")
     if not mongo_events:
         return 0
     return mongo_events[0].version
Ejemplo n.º 9
0
 def list_all_events_from_version(self, start_version: int, end_version: int = None):
     res = MongoEvent.get_base_events_by_version(self.server_id, start_version, end_version)
     return res
Ejemplo n.º 10
0
 def get_latest_version(self, key: str, namespace: str = None):
     mongo_events = MongoEvent.get_by_key(key, 0, 1, "-version")
     if not mongo_events:
         return 0
     return mongo_events[0].version