Beispiel #1
0
 def __exit__(self, exc_type, exc_value, traceback):
     self.close()
     with DB.connection_context():
         rows = SessionRecord.delete().where(
             SessionRecord.f_session_id == self._session_id).execute()
         if rows > 0:
             LOGGER.debug(f"delete session {self._session_id} record")
         else:
             LOGGER.warning(
                 f"failed delete session {self._session_id} record")
Beispiel #2
0
 def destroy_session(self):
     try:
         self.close()
     except:
         pass
     with DB.connection_context():
         rows = SessionRecord.delete().where(
             SessionRecord.f_session_id == self._session_id).execute()
         if rows > 0:
             LOGGER.debug(f"delete session {self._session_id} record")
         else:
             LOGGER.warning(
                 f"failed delete session {self._session_id} record")
Beispiel #3
0
 def __enter__(self):
     with DB.connection_context():
         session_record = SessionRecord()
         session_record.f_session_id = self._session_id
         session_record.f_engine_name = self._engine_name
         session_record.f_engine_type = EngineType.STORAGE
         # TODO: engine address
         session_record.f_engine_address = {}
         session_record.f_create_time = current_timestamp()
         rows = session_record.save(force_insert=True)
         if rows != 1:
             raise Exception(
                 f"create session record {self._session_id} failed")
         LOGGER.debug(f"save session {self._session_id} record")
     self.create()
     return self
Beispiel #4
0
 def query_expired_sessions_record(cls, ttl) -> [SessionRecord]:
     sessions_record = SessionRecord.select().where(
         SessionRecord.f_create_time < (current_timestamp() - ttl))
     return [session_record for session_record in sessions_record]