log only 5 min after game end + some type hinting :P

This commit is contained in:
Zutatensuppe 2021-05-31 20:05:41 +02:00
parent c2da0759b9
commit 870f827e49
9 changed files with 108 additions and 56 deletions

View file

@ -1,11 +1,27 @@
import fs from 'fs'
import readline from 'readline'
import stream from 'stream'
import Time from '../common/Time'
import { Timestamp } from '../common/Types'
import { logger } from './../common/Util'
import { DATA_DIR } from './../server/Dirs'
const log = logger('GameLog.js')
const POST_GAME_LOG_DURATION = 5 * Time.MIN
const shouldLog = (finishTs: Timestamp, currentTs: Timestamp): boolean => {
// when not finished yet, always log
if (!finishTs) {
return true
}
// in finished games, log max POST_GAME_LOG_DURATION after
// the game finished, to record winning dance moves etc :P
const timeSinceGameEnd = currentTs - finishTs
return timeSinceGameEnd <= POST_GAME_LOG_DURATION
}
const filename = (gameId: string) => `${DATA_DIR}/log_${gameId}.log`
const create = (gameId: string): void => {
@ -66,6 +82,7 @@ const get = async (
}
export default {
shouldLog,
create,
exists,
log: _log,