Server logger: add roomIndex and playStatus

This commit is contained in:
albertosottile 2018-07-25 15:40:37 +02:00
parent 9f52834ae4
commit c32bd1191c
2 changed files with 8 additions and 5 deletions

View File

@ -53,7 +53,7 @@ DIFFERENT_DURATION_THRESHOLD = 2.5
PROTOCOL_TIMEOUT = 12.5
RECONNECT_RETRIES = 999
SERVER_STATE_INTERVAL = 1
SERVER_LOG_SNAPSHOT_INTERVAL = 1
SERVER_LOG_SNAPSHOT_INTERVAL = 3600
WARNING_OSD_MESSAGES_LOOP_INTERVAL = 1
AUTOPLAY_DELAY = 3.0
DO_NOT_RESET_POSITION_THRESHOLD = 1.0

View File

@ -44,7 +44,8 @@ class SyncFactory(Factory):
self._roomManager = PublicRoomManager()
if logDbFile is not None:
self.logDbHandle = self._connectToLogDb(logDbFile)
reactor.callLater(0.1, self._scheduleVersionSnapshot, self.logDbHandle, self.port)
logDelay = 5*(int(self.port)%10 + 1)
reactor.callLater(logDelay, self._scheduleVersionSnapshot, self.logDbHandle, self.port)
else:
self.logDbHandle = None
@ -196,7 +197,7 @@ class SyncFactory(Factory):
def _connectToLogDb(self, dbPath):
conn = sqlite3.connect(dbPath)
c = conn.cursor()
c.execute('create table if not exists versionSnapshots (snapshotTime integer, port integer, version string)')
c.execute('create table if not exists versionSnapshots (snapshotTime integer, port integer, version string, roomIndex integer, playStatus integer)')
conn.commit()
return conn
@ -282,9 +283,11 @@ class PublicRoomManager(RoomManager):
def runVersionSnapshot(self, dbHandler, portNumber):
snapshotTime = str(int(time.time()))
c = dbHandler.cursor()
for room in self._rooms.values():
for idx, room in enumerate(self._rooms.values()):
playStatus = str(room.isPlaying())
for watcher in room.getWatchers():
c.execute("INSERT INTO versionSnapshots VALUES (" + snapshotTime + ", " + str(portNumber) + ", '" + watcher.getVersion() + "')")
c.execute("INSERT INTO versionSnapshots VALUES (" + snapshotTime + ", " + str(portNumber) +
", '" + watcher.getVersion() + "', " + str(idx) + ", " + playStatus + ")")
dbHandler.commit()